0

Hi I want to change look for all ComboBoxes in my app.

MyComboBox class:

class MyComboBoxUI extends BasicComboBoxUI {


    public static ComponentUI createUI(JComponent c) {
        return new MyComboBoxUI();
    }

    protected JButton createArrowButton() {
        JButton button = new BasicArrowButton(BasicArrowButton.EAST);
        return button;
    }
}

And i call it like this:

UIManager.put("ComboBoxUI", "MyComboBoxUI");

It produces this error:

UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JComboBox

When i use:

someComboBox.setUI((ComboBoxUI) MyComboBoxUI.createUI(someComboBox));

It works like a charm

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Zolkovv
  • 13
  • 4
  • Have you tried using the fully qualified class name of MyComboBoxUI when setting it to the UIManager – MadProgrammer Dec 23 '13 at 21:10
  • I dont know exactly how to do it. I treid: `put("ComboBoxUI", "com.zad2.okna.MyComboBoxUI")` and it didnt work – Zolkovv Dec 23 '13 at 21:17
  • The fully qualified name of the class is the package + class name – MadProgrammer Dec 23 '13 at 21:19
  • `com.zad2.okna.MyComboBoxUI` is package + class name. – Zolkovv Dec 23 '13 at 21:23
  • Ok i was able to make it work. My mistake was creating class MyComboBoxUI inside the same file where i was calling it by `UIManager.put("ComboBoxUI", "MyComboBoxUI");`. When i have moved it to different file it started to work with fully qualified class name. – Zolkovv Dec 23 '13 at 21:24
  • Right, try using UIManager.put("ComboBoxUI", "com.zad2.okna.MyComboBoxUI"); – MadProgrammer Dec 23 '13 at 21:24
  • 1
    1. right is only about the fully qualified name of the class ..., by assuming that MyComboBoxUI isn't compiled in separate jar, 2. please whats someComboBox.setUI((ComboBoxUI) MyComboBoxUI.createUI(someComboBox)); – mKorbel Dec 23 '13 at 21:33

0 Answers0