But if I use the setBackBround method to change the background color it seems not work.
To reproduce the problem use the following code.
When you choose a new color the background color is set on both styledLabel and button.
- Code: Select all
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.jidesoft.combobox.ColorChooserPanel;
import com.jidesoft.icons.JideIconsFactory;
import com.jidesoft.swing.*;
public class StyledLabelBug {
public static void main(String[] args) {
final JFrame f = new JFrame("StyledLabel Test");
f.getContentPane().setLayout(new BorderLayout());
final StyledLabel lab = new StyledLabel(JideIconsFactory.getImageIcon(JideIconsFactory.JIDE32));
lab.setText("colored text");
lab.setStyleRange(new StyleRange(0,7,StyleRange.STYLE_WAVED,Color.RED));
f.getContentPane().add(lab,BorderLayout.WEST);
final JButton b = new JButton("BackGround color ... ");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
ColorChooserPanel p = new ColorChooserPanel(ColorChooserPanel.PALETTE_COLOR_15);
p.setVisible(true);
final JDialog d = new JDialog(f,"color",true);
d.getContentPane().setLayout(new BorderLayout());
d.getContentPane().add(p,BorderLayout.CENTER);
JButton close = new JButton("Close");
close.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
d.dispose();
}});
d.getContentPane().add(close,BorderLayout.SOUTH);
d.setLocationRelativeTo(f);
d.pack();
d.setVisible(true);
lab.setBackground(p.getSelectedColor());
b.setBackground(p.getSelectedColor());
}});
f.getContentPane().add(b,BorderLayout.CENTER);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
JideSwingUtilities.globalCenterWindow(f);
f.setVisible(true);
}
}
Another problem regards the use of the styledLabel as treeCellRenderer because the Styled label often is cut at the end.