Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Readable output

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

861 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