I am trying to extend UI on some instances of JButton. The text and my test lines are visible, but no standard JButton border nor background for system LaF (Windows in my case). Only Motif works fine (see at the bottom).
JButton m_button = new JButton ();
QButtonUI m_ui = QButtonUI.createUI(m_button);
...
public class QButtonUI extends BasicButtonUI {
public QButtonUI() {
}
public static QButtonUI createUI(JButton c) {
QButtonUI ui = new QButtonUI();
c.setUI(ui);
return ui;
}
protected void paintButtonPressed(Graphics g, AbstractButton b) {
super.paintButtonPressed(g, b);
g.setColor(Color.RED);
g.drawLine(0, 0, 20, 20);
}
public void update(Graphics g, JComponent c) {
super.update(g, c);
g.setColor(Color.ORANGE);
g.drawLine(0, 20, 20, 0);
}
}
In fact:
- WindowsLookAndFeel and NimbusLookAndFeel don't work - no border and no background, just text.
- Default (metal) and WindowsClassic: have border but no background (not sure if WindowsClassic has a background)
- Motif works fine and looks great
Looks like an incomplete implementation but I'll leave the question in case I missed a call or param.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");