Reputation: 1
I want to take a value from a combo box and insert it in a method. My problem is the method needs to take variable of type Node.
ShortestPath.computeRoutes(jComboBoxDepFrom.getSelectedItem().toString());
When I try the above code I get the following error:
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
Upvotes: 0
Views: 1150
Reputation: 109547
You could place Nodes in the combobox, and use a renderer for the text per Node.
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);
};
});
If the Node.toString does not suffice.
Upvotes: 2