2012-04-23 4 views
0

콤보 상자에서 값을 가져 와서 메서드에 삽입하고 싶습니다. 내 문제는 메서드는 Node 형식의 변수를 사용해야합니다.자바 netbeans 양식 - 콤보 상자에서 값을 받아

ShortestPath.computeRoutes(jComboBoxDepFrom.getSelectedItem().toString());

나는 다음과 같은 오류가 위의 코드하려고 할 때 :

method computeRoutes in class busplanner.ShortestPath cannot be applied to given types; required: busplanner.Node found: java.lang.String reason: actual argument java.lang.String cannot be converted to busplanner.Node by method invocation conversion

+2

[SSCCE] (http://sscce.org/)로 질문을 수정하십시오. – mKorbel

+0

Node 클래스에 문자열을 사용하는 생성자 나 설정자가 없습니까? – THelper

답변

2

당신은 콤보 상자에 노드를 배치하고 노드 당 텍스트 렌더러를 사용할 수 있습니다.

jComboBoxDepFrom.setRenderer(new BasicComboBoxRenderer() { 

    @Override 
    public Component getListCellRendererComponent(JList list, 
               Object value, 
               int index, 
               boolean isSelected, 
               boolean cellHasFocus) { 
     Node node = (Node)value; 
     return super.getListCellRendererComponent(list, node.getText(), 
       index, isSelected, cellHasFocus); 
    }; 
}); 

Node.toString으로 충분하지 않은 경우

관련 문제