user2082985
user2082985

Reputation: 85

Java JPanel combobox that holds object types

So far from what I have seen combo boxes can only hold string and int types of values but this is what I am trying to achieve.

Class Node
{
  //code here
}

Node a = new Node();
Node b = new Node();

//I am wondering if I can somehow achieve something like
Node item = comboBox.getSelectedItem();

So I want the combo box to hold items of type Node. The combo box will allow for a and b values but when selected they will register as Node objects. I am not sure that is even possible but just wondering. Thanks for input :)

Upvotes: 0

Views: 221

Answers (1)

P. Lalonde
P. Lalonde

Reputation: 694

Yes, JComboBox is able to contain any type of Object. As of 1.7, you can also use the template definition to define the type contained.

Upvotes: 1

Related Questions