1. swingx
  2. SWINGX-1449

JXButton doesn't update font if background is modified


    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6.2, 1.6.3, 1.6.4
    • Fix Version/s: 1.6.5
    • Component/s: Misc Component
    • Labels:
    • Environment:

      Java SE 6 SDK 1.6.0u25
      Windows 7 (64 bit)
      Latest SwingX build


      If you set font on a button and later you modify either background color or painter, the font is restored back to normal. Not only that, if you notice, when you set background painter the font is drawn slightly bolder.

      The following code illustrates the case comparing JButton and JXButton behaviors:

      import java.awt.Color;
      import java.awt.Container;
      import java.awt.Font;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.SwingConstants;
      import org.jdesktop.swingx.HorizontalLayout;
      import org.jdesktop.swingx.JXButton;
      import org.jdesktop.swingx.JXLabel;
      import org.jdesktop.swingx.JXPanel;
      import org.jdesktop.swingx.VerticalLayout;
      import org.jdesktop.swingx.painter.MattePainter;
      import org.jdesktop.swingx.painter.Painter;

      public class JXButtonFontAndBackgroundTest {

      public static void main(String... args)

      { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JXButton .setFont(), .setBackground() and .setBackgroundPainter() test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = Font.decode("Arial-BOLDITALIC-14"); Color background = Color.LIGHT_GRAY; Painter<?> backgroundPainter = new MattePainter(background); JButton button1 = new JButton("Default"); JButton button2 = new JButton("Font changed"); button2.setFont(font); JButton button3 = new JButton("Background changed"); button3.setBackground(background); JButton button4 = new JButton("Background changed"); button4.setBackground(background); // button4.setBackgroundPainter(backgroundPainter); JButton button5 = new JButton("Font and Background changed"); button5.setFont(font); button5.setBackground(background); JButton button6 = new JButton("Font and Background changed"); button6.setFont(font); button6.setBackground(background); // button6.setBackgroundPainter(backgroundPainter); JXButton xbutton1 = new JXButton("Default"); JXButton xbutton2 = new JXButton("Font changed"); xbutton2.setFont(font); JXButton xbutton3 = new JXButton("Background changed"); xbutton3.setBackground(background); JXButton xbutton4 = new JXButton("BackgroundPainter changed"); xbutton4.setBackgroundPainter(backgroundPainter); JXButton xbutton5 = new JXButton("Font and Background changed"); xbutton5.setFont(font); xbutton5.setBackground(background); JXButton xbutton6 = new JXButton("Font and BackgroundPainter changed"); xbutton6.setFont(font); xbutton6.setBackgroundPainter(backgroundPainter); JXPanel panel = new JXPanel(new VerticalLayout()); panel.add(new JXLabel(JButton.class.getSimpleName(), SwingConstants.CENTER)); panel.add(button1); panel.add(button2); panel.add(button3); panel.add(button4); panel.add(button5); panel.add(button6); JXPanel xpanel = new JXPanel(new VerticalLayout()); xpanel.add(new JXLabel(JXButton.class.getSimpleName(), SwingConstants.CENTER)); xpanel.setLayout(new VerticalLayout()); xpanel.add(xbutton1); xpanel.add(xbutton2); xpanel.add(xbutton3); xpanel.add(xbutton4); xpanel.add(xbutton5); xpanel.add(xbutton6); Container contentPane = frame.getContentPane(); contentPane.setLayout(new HorizontalLayout()); contentPane.add(panel); contentPane.add(xpanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }



        No work has yet been logged on this issue.


          • Assignee:
            Karl Schaefer
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: