请问如何JLable改变的颜色?用setBackground(color),好象不行。 与layout无关。应该是你的代码的问题。自己再看一下,或者把代码帖出来。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把你的bannerPanel的颜色改一下。bannerPanel.setBackground(tmpColor);试试看。 是啊,你应该修改的是panel的背景色 to fastmask and eshen2002:该了bannerPanel:改变的背景太大了。我只要BannerPanel中间的banner一块改变就可以了。to namowen: code is bellowing: this.getContentPane().setLayout(verticalFlowLayout1); tcc = new JColorChooser(tmpColor); //Set up preview pane final JLabel banner = new JLabel("*** This is selected Color ***", JLabel.CENTER); banner.setBackground(tmpColor); banner.setForeground(Color.black); banner.setPreferredSize(new Dimension(100, 65)); bannerPanel = new JPanel(new BorderLayout()); jButton1.setText("OK"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jButton2.setText("CANCEL"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton2_actionPerformed(e); } }); panel2.setLayout(xYLayout1); bannerPanel.add(banner, BorderLayout.CENTER); bannerPanel.setBorder(BorderFactory.createTitledBorder("Text Color")); tcc.setPreviewPanel(new JPanel()); tcc.getSelectionModel().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { tmpColor = tcc.getColor(); banner.setBackground(tmpColor); } }); tcc.setBorder(BorderFactory.createTitledBorder( "Choose Text Color")); //Add the components to the frame Container contentPane = getContentPane(); contentPane.add(bannerPanel, BorderLayout.SOUTH); contentPane.add(tcc, BorderLayout.CENTER); panel1.setLayout(borderLayout1); getContentPane().add(panel1, null); this.getContentPane().add(panel2, null); panel2.add(jButton1, new XYConstraints(36, 3, 87, 24)); panel2.add(jButton2, new XYConstraints(279, 4, 88, 23)); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { tmpColor = tcc.getColor(); } }); 你把label的背景色设成你想要的,然后修改label的不透明属性设为true,就行里。 thanks for the advice, fastmask :) ^-^ Eclipse3.7.2可视化开发?如何实现?谢谢! netbeans里jtable,排序后,增加新纪录发现游标指向混乱 如何给自己创建的SWT添加属性 高分请教各位老大们两大问题。 Dialog弹出问题II java中的密码框?? java字符串中将"替换成\"输出,如何解决. 怎么样设置classpath 给高中生教java程序设计,各位推荐一些入门的java教材 List集合删除元素 window xp不支持java? 怎样把整型化为字符型?
bannerPanel.setBackground(tmpColor);
试试看。
该了bannerPanel:改变的背景太大了。我只要BannerPanel中间的banner一块改变就可以了。to namowen: code is bellowing:
this.getContentPane().setLayout(verticalFlowLayout1); tcc = new JColorChooser(tmpColor);
//Set up preview pane
final JLabel banner = new JLabel("*** This is selected Color ***",
JLabel.CENTER);
banner.setBackground(tmpColor);
banner.setForeground(Color.black);
banner.setPreferredSize(new Dimension(100, 65)); bannerPanel = new JPanel(new BorderLayout());
jButton1.setText("OK");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setText("CANCEL");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
panel2.setLayout(xYLayout1);
bannerPanel.add(banner, BorderLayout.CENTER);
bannerPanel.setBorder(BorderFactory.createTitledBorder("Text Color")); tcc.setPreviewPanel(new JPanel());
tcc.getSelectionModel().addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
tmpColor = tcc.getColor();
banner.setBackground(tmpColor); }
});
tcc.setBorder(BorderFactory.createTitledBorder(
"Choose Text Color"));
//Add the components to the frame
Container contentPane = getContentPane();
contentPane.add(bannerPanel, BorderLayout.SOUTH);
contentPane.add(tcc, BorderLayout.CENTER); panel1.setLayout(borderLayout1);
getContentPane().add(panel1, null);
this.getContentPane().add(panel2, null);
panel2.add(jButton1, new XYConstraints(36, 3, 87, 24));
panel2.add(jButton2, new XYConstraints(279, 4, 88, 23)); this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
tmpColor = tcc.getColor();
}
});