• Post Reply Bookmark Topic Watch Topic
  • New Topic

even though setting the label color is not displaying

 
damodar kumar
Ranch Hand
Posts: 77
Android Chrome MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

even though setting the label color is not displaying, here im pasting the code .please help.


package chessboard.gui;
import javax.swing.Icon;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Label;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

//import statements
//Check if window closes automatically. Otherwise add suitable code
public class chessboard extends JFrame {


void chessboard() {

Border blackline ;
//frame.getContentPane().add(label);
try{


//Color black = new Color(0, 0, 0);
//Color red = new Color(255, 0, 0);
// Icon icon = new DiamondIcon(Color.red, true, 25, 25);


blackline = BorderFactory.createLoweredBevelBorder();
JFrame frame = new JFrame("ChessBoard");
JLabel label = new JLabel("hi");
JLabel label1 = new JLabel("how");
frame.getContentPane().setLayout(new GridLayout(8,8,0,0));
label.setBorder(blackline);
label.setBackground(Color.pink);
label.setName("A");
label.setSize(30,30);
frame.getContentPane().add(label);
frame.getContentPane().add(label1);
label.setVisible(true);
label1.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setSize(800,800);
frame.setVisible(true);
}catch(Exception e){
System.out.println("Exceptoin id"+e);
}
}
public static void main(String args[]) {
chessboard ch = new chessboard();
ch.chessboard();
}
}



Thanks,

Dam
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by damodar kumar:

even though setting the label color is not displaying, here im pasting the code .please help.


JLabels, by default, are transperant. You need to call for the background color to show up on the UI.

Also, please use the CODE tags in the future to make your code readable and more understandable.
[ September 23, 2008: Message edited by: Maneesh Godbole ]
 
damodar kumar
Ranch Hand
Posts: 77
Android Chrome MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks its working.

Thanks,

Damodar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!