jtree는 jlist를 가지고 있고, jlist는 jtree 노드가 선택되어 있는지에 따라 다릅니다. 노드 색상을 선택하면 jlist가 두 항목을 추가합니다. 그런 다음 jlist에서 선택된 값을 넣는 jTextfield가 있습니다.선택 취소 jList
제 문제는 jlist의 값을 갖는 jTree에서 다른 노드를 선택하려고 할 때입니다.
이
내가 jTreeValueChanged의 행동이 무엇을private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt) {
jTextField1.setText("");
jList1.clearSelection();
jList1.repaint();
//DefaultMutableTreeNode seleccion;
seleccion=(DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();
if(seleccion.toString()=="colors"){
jList1.setModel(model );
model.addElement("rojo");
model.addElement("azul");
}
else if(seleccion.toString()=="sports"){
jList1.setModel(model);
model.addElement("futbol");
model.addElement("beisbol");
}
}
지금 이것은 jListValueChanged에 Thew 보낸 코드 :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at navegacion.arbolconlist.jList1ValueChanged(arbolconlist.java:124)
at navegacion.arbolconlist.access$100(arbolconlist.java:17)
at navegacion.arbolconlist$2.valueChanged(arbolconlist.java:60)
at javax.swing.JList.fireSelectionValueChanged(JList.java:1796)
at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1810)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:405)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:415)
at javax.swing.DefaultListSelectionModel.removeSelectionIntervalImpl(DefaultListSelectionModel.java:576)
at javax.swing.DefaultListSelectionModel.clearSelection(DefaultListSelectionModel.java:420)
at javax.swing.JList.clearSelection(JList.java:2043)
at navegacion.arbolconlist.jTree1ValueChanged(arbolconlist.java:101)
at navegacion.arbolconlist.access$000(arbolconlist.java:17)
at navegacion.arbolconlist$1.valueChanged(arbolconlist.java:53)
at javax.swing.JTree.fireValueChanged(JTree.java:2921)
at javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:3382)
at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:635)
at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1093)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:294)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:188)
at javax.swing.JTree.setSelectionPath(JTree.java:1633)
at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2393)
at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3609)
at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:3548)
at java.awt.Component.processMouseEvent(Component.java:6524)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6292)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4883)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4530)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:719)
at java.awt.EventQueue$4.run(EventQueue.java:717)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
:
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {
String seleccion =jList1.getSelectedValue().toString();
jTextField1.setText(seleccion);
}
내가 다른 노드를 선택하면 예외가가
'seleccion.toString() == "colors"'는 좋지 않습니다. 보십시오 [어떻게 - 할 - 비교 - 문자열 - 자바에서] (http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Pshemo
당신을 위해 감사합니다 의견, 나는 그것을 고칠 수 있지만 다른 노드를 선택했을 때 나는 여전히 같은 문제가 있습니다. 내가 무엇을 할 수 있는지 알고 있니? –