Apache NetBeans
Apache NetBeans
Latest release

Apache NetBeans 24

Download

How can I graphically create a ChoiceView in using the GUI designer?

It is possible to use a ChoiceView graphically during the design of your interface in the Form Editor. As ChoiceView extends JComboBox, you can design the interface with the help of a JComboBox which is the placeholder for your ChoiceView and customize the creation code of the combo to instantiate a ChoiceView instead.

Simply choose "Combo Box" from the "Swing Controls" palette and drop it onto your interface. Then select the combo and select the "Code" tab in the properties window. In the "custom creation code" field type: "new ChoiceView()". Then return to the "Properties" tab an clear the "model" field. This step is absolutely mandatory otherwise it won’t work: by default the Form Editor creates a dummy model for you. It is forbidden to set a model on a ChoiceView. If you do anyway you will get errors like:

java.lang.ClassCastException: java.lang.String cannot be cast to org.openide.explorer.view.VisualizerNode
        at org.openide.explorer.view.NodeRenderer.findVisualizerNode(NodeRenderer.java:232)
        at org.openide.explorer.view.NodeRenderer.getListCellRendererComponent(NodeRenderer.java:152)
        at javax.swing.plaf.basic.BasicComboBoxUI.paintCurrentValue(BasicComboBoxUI.java:1202)
        at com.sun.java.swing.plaf.windows.WindowsComboBoxUI.paintCurrentValue(WindowsComboBoxUI.java:293)
        at javax.swing.plaf.basic.BasicComboBoxUI.paint(BasicComboBoxUI.java:888)
        at com.sun.java.swing.plaf.windows.WindowsComboBoxUI.paint(WindowsComboBoxUI.java:199)
        at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
        at javax.swing.JComponent.paintComponent(JComponent.java:763)
        at javax.swing.JComponent.paint(JComponent.java:1029)
        at javax.swing.JComponent.paintChildren(JComponent.java:864)
        at javax.swing.JComponent.paint(JComponent.java:1038)
        at javax.swing.JComponent.paintChildren(JComponent.java:864)
        at javax.swing.JComponent.paint(JComponent.java:1038)
   ...

Finally switch to the "Source" view and fix the import errors. --Tim Boudreau