Revision as of 02:40, 24 January 2010 by Tboudreau (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)

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( 
        at org.openide.explorer.view.NodeRenderer.getListCellRendererComponent( 
        at javax.swing.plaf.basic.BasicComboBoxUI.paintCurrentValue( 
        at javax.swing.plaf.basic.BasicComboBoxUI.paint( 
        at javax.swing.plaf.ComponentUI.update( 
        at javax.swing.JComponent.paintComponent( 
        at javax.swing.JComponent.paint( 
        at javax.swing.JComponent.paintChildren( 
        at javax.swing.JComponent.paint( 
        at javax.swing.JComponent.paintChildren( 
        at javax.swing.JComponent.paint( 

Finally switch to the "Source" view and fix the import errors. --Tboudreau 02:40, 24 January 2010 (UTC)

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo