Hi guys!
Can you help me please:
I have a combo box and 3 items there: Text1, Text2, Text3.
Default is Text1.
If I change from Text1 to Text2 or to Text3, button at the bottom must change its color.
Any change must show in the button by color changing.
Thanks.
3 replies to this topic
#1
Posted 03 January 2012 - 11:07 PM
|
|
|
#2
Posted 04 January 2012 - 12:39 PM
You mean something like this?
<html>
<head>
<script type="text/javascript">
function doSomething()
{
var colors = new Array( "Red", "Green", "Blue", "Orange" );
var dropDown = document.getElementById("selectId");
dropDown.style.backgroundColor = colors[dropDown.selectedIndex];
}
</script>
</head>
<body>
<form>
<select id="selectId" name="cars" onChange="doSomething()">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat" selected="selected">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>
</body>
</html>
-CDG10620
Software Developer
Software Developer
#3
Posted 04 January 2012 - 01:52 PM
I take it since this was posted in the Java forum, he is talking about combo boxes in either Swing or SWT.
What you are going to need to do is add an ActionListener to your combo box. JComboBox fires an ActionEvent any time the user selects an item from the list, which is what you want in your case.
Here's a very simple example of adding an ActionListener to a JComboBox:
What you are going to need to do is add an ActionListener to your combo box. JComboBox fires an ActionEvent any time the user selects an item from the list, which is what you want in your case.
Here's a very simple example of adding an ActionListener to a JComboBox:
JComboBox jCombo = new JComboBox();
... // add your selection items here.
jCombo.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JComboBox source = (JComboBox) e.getSource(); // This gets the source control which originated the event.
String selection = (String) source.getSelectedItem(); // This gets the text that was selected by the user.
... // Now you can do something with this information here.
}
}
);
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#4
Posted 04 January 2012 - 08:45 PM
Yep, I meant the swing. Thanks gregwarner, I understood it. :rolleyes:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









