StyledLabel and backGround

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

StyledLabel and backGround

Postby nicola.gioia » Wed Dec 13, 2006 4:59 am

I used the StyledLabel, to customize the font color , and if I use the setForeground method on the styledLabel it correctly change the color of the uncustomized part of the label.
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.
nicola.gioia
 
Posts: 60
Joined: Tue Sep 20, 2005 6:57 am

Postby nicola.gioia » Wed Dec 13, 2006 7:33 am

I resolved all problem...
For the renderer I used the StyledLabelTreeRenderer, and for the StyledLabel I called the setOpaque(true) method.
Thanks and sorry
nicola.gioia
 
Posts: 60
Joined: Tue Sep 20, 2005 6:57 am

Postby JIDE Support » Wed Dec 13, 2006 9:08 am

That's correct. StyledLabel, just like JLabel, is transparent by default.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 82 guests