473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

buttons and combo boxes

Hi,
I know how to do an action listener with a button but now I want to try
something a bit harder. This is what I want to do...
When you user presses the JButton it looks at the JComboBox to see if it is
selected.
If it is, a sound is played.
If it isn't, nothing happens.
I'm not sure how to do this so if someone could give me a simple example or
send me on the write track I would very much appreciate it.
Thanks alot
Matt
Jul 17 '05 #1
2 3287
Matt,

When you say the look to see if the JComboBox is selected, do you mean
see if a selection from the list has been chosen, or does the JComboBox
currently have the focus (ie has been clicked on last)?

If it's the first option, the best bet is to have a blank value in the
first selection, and in your code check...
if(comboBox.getSelectedIndex==0) {
//do nothing as first option chosen
} else {
//do something else
}

If it's the latter option, you would use comboBox.hasFocus()

Hope this is what you were looking for :)
webstar wrote:
Hi,
I know how to do an action listener with a button but now I want to try
something a bit harder. This is what I want to do...
When you user presses the JButton it looks at the JComboBox to see if it is
selected.
If it is, a sound is played.
If it isn't, nothing happens.
I'm not sure how to do this so if someone could give me a simple example or
send me on the write track I would very much appreciate it.
Thanks alot
Matt


Jul 17 '05 #2
Liz
I was under the impression that if you clicked on
a button that the button would have the focus?

"Pete" <pc********@iprimus.com.au> wrote in message news:3f**********@news.iprimus.com.au...
Matt,

When you say the look to see if the JComboBox is selected, do you mean
see if a selection from the list has been chosen, or does the JComboBox
currently have the focus (ie has been clicked on last)?

If it's the first option, the best bet is to have a blank value in the
first selection, and in your code check...
if(comboBox.getSelectedIndex==0) {
//do nothing as first option chosen
} else {
//do something else
}

If it's the latter option, you would use comboBox.hasFocus()

Hope this is what you were looking for :)


webstar wrote:
Hi,
I know how to do an action listener with a button but now I want to try
something a bit harder. This is what I want to do...
When you user presses the JButton it looks at the JComboBox to see if it is
selected.
If it is, a sound is played.
If it isn't, nothing happens.
I'm not sure how to do this so if someone could give me a simple example or
send me on the write track I would very much appreciate it.
Thanks alot
Matt


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Krisa | last post by:
Hello all, I just discovered something (stop me if you've heard this before....) that was causing me a significant performance hit when opening a form with subforms. To speed up loading the...
0
by: Robert | last post by:
Stephen, I think I figured out the problem. I was able to get Check Boxes and Option Buttons to work on my form by TURNING OFF RECORD SELECTORS on the form. Not sure why this would make a...
0
by: Tom | last post by:
I have some very strange issues with combo boxes on a tab control. Here's the scenario: I have a Windows Forms form that has a tab control on it, with two (2) tabs. Tab 2 happens to have a number...
4
by: Dave | last post by:
I wasn't sure how to search for previous posts about this, it felt real specific. Ok so here's the database & problem: I have 4 combo boxes: cboServer, cboPolicy, cboDB, and cboApplication. ...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
10
by: Lindsay Browning | last post by:
Hello, I found a previous posting by someone on the 10th Sept (http://www.thescripts.com/forum/thread705528.html) who seemed to have the same problem as me, but it was never resolved. I have...
2
by: someshbakliwal | last post by:
Hi, I have created some autopopulating combo boxes on my HTML page (script- Javascript). so these combo boxes are autopopulated with choices made in previous combo boxes. The problem I am facing is...
2
beacon
by: beacon | last post by:
Hi everybody, I have a form that has a combo box that asks the user to select the program they work on. Once the user selects the program, a SQL statement populates the row source for 4 staff...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.