Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-13-2008, 12:13 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 235
willemjav is on a distinguished road
mirrors in mirrors in JMenu
Imagine there is a dropdown menu with several color items.
(black, white, red, blue, green and yellow)
Just one color should appear selected (no-color-selected is not a option.
I taught the next code would do it!
(but I believe there is some funny backfiring loop because resetColormenu()
will call itemStateChanged(ItemEvent evt) etc.)
There should be an other way without back looping?

public void itemStateChanged(ItemEvent evt) {
Object source = evt.getSource();
if ( blacktxt.isSelected() ) {
resetColormenu();
blacktxt.setSelected(true);
img[index].infotextcolor = "black";
}
else
if ( whitetxt.isSelected() ) {
resetColormenu();
whitetxt.setSelected(true);
img[index].infotextcolor = "white";
}
else
if ( bluetxt.isSelected() ) {
resetColormenu();
bluetxt.setSelected(true);
img[index].infotextcolor = "blue";
}
else
if ( redtxt.isSelected() ) {
resetColormenu();
redtxt.setSelected(true);
img[index].infotextcolor = "red";
}
else
if ( yellowtxt.isSelected() ) {
resetColormenu();
yellowtxt.setSelected(true);
img[index].infotextcolor = "yellow";
}
else
if ( greentxt.isSelected() ) {
resetColormenu();
greentxt.setSelected(true);
img[index].infotextcolor = "green";
}


}


private void resetColormenu() {
blacktxt.setSelected(false);
whitetxt.setSelected(false);
bluetxt.setSelected(false);
redtxt.setSelected(false);
yellowtxt.setSelected(false);
greentxt.setSelected(false);
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-13-2008, 12:36 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 235
willemjav is on a distinguished road
okay i found the answer myself
it is called a JRadioButtonMenuItem
thanks to myself
willemjav
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-14-2008, 08:04 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
To get the ItemListener to work try:
Code:
if(e.getStateChange() == ItemEvent.SELECTED) { // your code here... }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-14-2008, 09:40 AM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 235
willemjav is on a distinguished road
I actually used this (probably your code is better)

public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();

//if (durationField==source) { // did not work
String str = durationField.getText(); // read out the duration field fields
img[index].duration = Integer.parseInt(str);


if ( blacktxt.isSelected()) {
img[index].infotextcolor = "black";
}
else
if ( whitetxt.isSelected()) {
img[index].infotextcolor = "white";
}
else

etc
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-14-2008, 12:53 PM
Senior Member
 
Join Date: Dec 2007
Location: Spain
Posts: 235
willemjav is on a distinguished road
Hardwired, what´s wrong here (cannot find var. SELECTED)?

public void itemStateChanged(ItemEvent evt) {
int x=0;
String str;
if(evt.getStateChange() == durationField.SELECTED) {
do {
str = durationField.getText();
try {
x = Integer.parseInt(str);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(infoPane,"please type number within range 1-360 + return");
ex.printStackTrace();
}
if (x<1 || x>360) JOptionPane.showMessageDialog(infoPane,"please type number within range 1-360 + return");
} while (x<1 || x>360);
img[index].duration = x;
}
}
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-14-2008, 07:59 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
Code:
// This is specifying a field "SELECTED" in the "durationField" // class instance. durationField.SELECTED // This is specifying a field "SELECTED" in the ItemEvent class. // See Field Summary section in ItemEvent api. ItemEvent.SELECTED
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting a JMenu paints over the JPanel on the content pane Swingset AWT / Swing 3 01-06-2008 12:13 AM
JMenu calling another Forms/Panels plodos New To Java 2 12-10-2007 09:02 AM
JMenu and JRadioButtonMenuItem doron70 AWT / Swing 3 07-18-2007 07:13 PM


All times are GMT +3. The time now is 09:15 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org