aspose file tools*
The moose likes Beginning Java and the fly likes Error When trying to display Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error When trying to display" Watch "Error When trying to display" New topic
Author

Error When trying to display

Jesse Walker
Ranch Hand

Joined: Aug 18, 2004
Posts: 50
I have tried to write a program that displays the selected item from a JList but what I get is the following LJava.lang.Object:@7ca8\

The following is my code(WHERE DID I GO WRONG???)

JFrame f = new JFrame("Order Please");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
String[] items = { "Ketchup", "Mustard", "Pickle", "Onion", "Tomato",
"Lettuce", "Mayonise"};
final JList list = new JList(items);
String [] items2 = {"Beef", "Chicken", "Beef", "Veggie"};
JComboBox maincourse = new JComboBox(items2);
JButton mybutton = new JButton("Print");
mybutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Object[] selection = list.getSelectedValues();
String[] selection2 = (String)selection;
System.out.print(selection);
}
});
Container content = new JPanel();
content.add(maincourse);
content.add(list);
content.add(mybutton);
f.setContentPane(content);
f.pack();
f.setLocation(300, 300);
f.setVisible(true);
Mattias Arthursson
Ranch Hand

Joined: Jul 26, 2004
Posts: 90
You are passing the entire array to println():


This will call toString() on your Object array, which will produce the output you're getting.

Try printlng out the contents of the array instead, e.g.:


Admit nothing. Blame everyone. Be bitter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error When trying to display