Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Readable output

Posted on 2006-12-01
3
Medium Priority
?
232 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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

783 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