Solved

Readable output

Posted on 2006-12-01
3
221 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
looking for unix program to search some keywords in side EAR WAR and JAR files 10 81
thymeleaf natural templating vs JSP 2 68
ForLoop Example 3 40
javap bin 2 29
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

867 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

15 Experts available now in Live!

Get 1:1 Help Now