Solved

Readable output

Posted on 2006-12-01
3
219 Views
Last Modified: 2010-03-31
Hey again,

objects was kind enough to supply me with the following code which solved my previous problem:

JComboBox comboxChanged;

public void actionPerformed(ActionEvent, e) {
comboxChanged = (JComboBox) e.getSource();
itemChanged();
}

public void itemchanged() {
switch(comboxChanged.getSelectedIndex()) {
case 0:
// something;
break;
case 1:
// something else;
break;
etc ...
}


Problem arrises when I try to output the variable combox, the output is just a string of rubbish about the comboBox [ bounds, colors etc ].  How can I turn this useless info into somthing useful ?

Kind Regards,
0
Comment
Question by:3nigmatic
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
colr__ earned 300 total points
ID: 18058159
comboBox is a non-string object, so when you call toString() on it, it prints out a string representation of the objetc, not any text that object may contain.

Use getSelectedItem() to get a reference to the selected object in comboBox. Then, depending on what that selected object is, you can get the info you need.

The selected object depends on what you added to the comboBox - if they were String's, then you already have what you need. If not, call any methods on that object that will give you the string you're looking for.
0
 
LVL 2

Author Comment

by:3nigmatic
ID: 18058166
Hey,

Thats almost it, getSelectedItem() prints out what has been selected ... I am trying to get ahold of the "name" of the combobox that was changed rather than the item that was selected.

Is this possible ?

Thanks for your time.
0
 
LVL 2

Author Comment

by:3nigmatic
ID: 18058373
Resolved the issue myself using setName() and getName() ... bit inefficient but it does the job and thats all I require at this time, thanks anyway.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now