Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with JDialog and setVisible

843805Feb 22 2006 — edited Feb 22 2006
Hi everyone,

i created a JDialog with three JLists, some JRadioButtons. To set the data of the JList i have separate methods and only after all data has been set i want the dialog to show. Therefore the following code:
                ChangeHierarchyDialog dialog =new ChangeHierarchyDialog(ChangeHierarchyDialog.MOVE, oCont);
                dialog.setClassName(ConceptListPanel.getSelected());
                Concept c = oCont.getConceptWithName(ConceptListPanel.getSelected());
                dialog.setSubClasses(c.getSubConceptNames()); //Just setting some Strings
                dialog.setSuperClasses(c.getSuperConceptNames()); //Just setting some Strings
                dialog.setAllClasses(oCont.getAllConceptNames()); //Just setting some Strings

                dialog.setVisible(true); //Here i get the exception
But for some reason i don't get i get the following exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at javax.swing.JList$5.getSize(JList.java:1249)
	at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1136)
	at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1105)
	at javax.swing.plaf.basic.BasicListUI.getPreferredSize(BasicListUI.java:356)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1615)
	at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:769)
	at java.awt.Container.layout(Container.java:1401)
	at java.awt.Container.doLayout(Container.java:1390)
	at java.awt.Container.validateTree(Container.java:1473)
	at java.awt.Container.validateTree(Container.java:1480)
	at java.awt.Container.validateTree(Container.java:1480)
	at java.awt.Container.validateTree(Container.java:1480)
	at java.awt.Container.validateTree(Container.java:1480)
	at java.awt.Container.validate(Container.java:1448)
	at java.awt.Dialog.conditionalShow(Dialog.java:443)
	at java.awt.Dialog.show(Dialog.java:506)
	at java.awt.Component.show(Component.java:1300)
	at java.awt.Component.setVisible(Component.java:1253)
	at ma.ui.editor.listeners.PopupListener.actionPerformed(PopupListener.java:95)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:334)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
	at java.awt.Component.processMouseEvent(Component.java:5554)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
	at java.awt.Component.processEvent(Component.java:5319)
	at java.awt.Container.processEvent(Container.java:2010)
	at java.awt.Component.dispatchEventImpl(Component.java:4021)
	at java.awt.Container.dispatchEventImpl(Container.java:2068)
	at java.awt.Component.dispatchEvent(Component.java:3869)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
	at java.awt.Container.dispatchEventImpl(Container.java:2054)
	at java.awt.Window.dispatchEventImpl(Window.java:1774)
	at java.awt.Component.dispatchEvent(Component.java:3869)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:275)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
In case you want to know here's the code of the JDialog:
public class ChangeHierarchyDialog extends JDialog implements ListSelectionListener{

    private JLabel _nameLabel = new JLabel();

    private JLabel _subclassLabel = new JLabel();


    private JLabel _superclassLabel = new JLabel();

    private XYLayout xYLayout1 = new XYLayout();

    private JList _subclassList = new JList();

    private JList _superclassList = new JList();

    private JRadioButton _subclassButton = new JRadioButton();

    private JRadioButton _superclassButton = new JRadioButton();

    private JList _allclassesList = new JList();

    private JButton _okButton = new JButton();

    private JButton _cancelButton = new JButton();
    
    public static final int MOVE = 0;
    public static final int COPY = 1;
    private int _changeMode;//0 -> Verschieben; 1 -> Kopieren
    private int _classChangeMode; //0->neue Unterklasse von; 1->neue Oberklasse von
    private OntologyContainer _oCont;
    //private Vector<String> _subC;
    private Vector<String> _superC;
    private String[] _selection;


    public ChangeHierarchyDialog(int mode, OntologyContainer ocont)
    {
        try
            {
                jbInit();
            }
        catch (Exception e)
            {
                e.printStackTrace();
            }
            
        _changeMode = mode;
        _oCont = ocont;
    }

    private void jbInit() throws Exception
    {
        this.getContentPane().setLayout(xYLayout1);
        this.setModal(true);
        this.setTitle("Klassenhierarchie �ndern");
        _nameLabel.setText("Text");
        _subclassLabel.setText("Unterklasse Von:");
        _superclassLabel.setText("�berklasse Von:");
        xYLayout1.setWidth(436);
        xYLayout1.setHeight(417);
        _subclassList.setDragEnabled(true);
        _superclassList.setEnabled(false);
        _subclassButton.setText("Unterklasse");
        _subclassButton.setActionCommand("subclass");
        _subclassButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {
                        setMode(e);
                    }
                });
        _superclassButton.setText("�berklasse");
        _superclassButton.setActionCommand("superclass");
        _superclassButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {
                        setMode(e);
                    }
                });
        _okButton.setText("OK");
        _okButton.setActionCommand("ok");
        _okButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {
                        changeHierarchy(e);
                    }
                });
        _cancelButton.setText("Abbrechen");
        _cancelButton.setActionCommand("cancel");
        _cancelButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e)
                    {
                        close(e);
                    }
                });
                
        JScrollPane sPaneSub = new JScrollPane(_subclassList);
        JScrollPane sPaneSuper = new JScrollPane(_superclassList);
        JScrollPane sPaneAll = new JScrollPane(_allclassesList);
        
        this.getContentPane().add(_cancelButton, new XYConstraints(220, 350, 115, 30));
        this.getContentPane().add(_okButton, new XYConstraints(20, 350, 115, 30));
        this.getContentPane().add(sPaneAll, new XYConstraints(220, 170, 180, 160));
        this.getContentPane().add(_superclassButton, new XYConstraints(10, 205, 150, 25));
        this.getContentPane().add(_subclassButton, new XYConstraints(10, 175, 150, 20));
        this.getContentPane().add(sPaneSuper, new XYConstraints(10, 65, 180, 95));
        this.getContentPane().add(sPaneSub, new XYConstraints(220, 65, 180, 95));
        this.getContentPane().add(_nameLabel, new XYConstraints(5, 5, 300, 25));
        this.getContentPane()
            .add(_subclassLabel, new XYConstraints(220, 35, 135, 15));
        this.getContentPane()
            .add(_superclassLabel, new XYConstraints(10, 35, 115, 15));
        
        this.setSize(436, 417);
        
    }
    
    public void setClassName(String name) {
        _nameLabel.setText(name);
    }
    
    public void setSubClasses(Vector<String> subC) {
        //_subC = subC;
        _subclassList.setListData(subC);
    }
    
    public void setSuperClasses(Vector<String> superC) {
        _superC = superC;
        _superclassList.setListData(superC);
    }
    
    public void setAllClasses(Vector<String> allC) {
        _allclassesList.setListData(allC);
    }

    private void changeHierarchy(ActionEvent e)
    {
        switch(_changeMode) {
            case 0:
                Editor ed = new Editor();
                ed.setOntologyContainer(_oCont);
                ed.moveClass(_nameLabel.getText(), _superC, _selection, _classChangeMode);
        }
        
    }

    private void close(ActionEvent e)
    {
        dispose();
    }

    private void setMode(ActionEvent e)
    {
        String cmd = e.getActionCommand();
        if(cmd.equals("subclass")) {
            _classChangeMode = 0;
        }
        else if(cmd.equals("superclass")) {
            _classChangeMode = 1;
        }
    }
    
    public void valueChanged(ListSelectionEvent lse) {
        if (lse.getValueIsAdjusting() == false) {

                if (_allclassesList.getSelectedIndex() != -1) {
                    _selection = (String[])_allclassesList.getSelectedValues();
                    System.out.println("ChangeDialog Selection size "+_selection.length);
                } 
                
            }
    }
}
Any idea? Because i really have no clue at all...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2006
Added on Feb 22 2006
1 comment
116 views