Results 1 to 4 of 4
  1. #1
    Paul_White is offline Member
    Join Date
    Apr 2011
    Rep Power

    Question Multiple JComboBoxes with listener etc.

    Firstly let me apologise if this has been answered elsewhere but I could not find an answer using the search function.
    I am writing what I beleive is a faily basic program which will access a mysql database, get results and then performa calculataions based on the results returned, then display the search criteria and calcualtion result.
    I have written the database integration using JDBC and also have the math part sorted both currently created as separate classes. The results of the sql query are public and can be seen by the calculation class.
    I have started the code the interrogate the database to return a list of tables but I think I need to use an array rather than a string as currently the result is only the last table in the database - I should be able to fix this myself.
    The second query interrogates one of the fields in the chosen table and returns a unique list of results again this is only giving me the last entry...
    Finally the third query gets a complete list of available choices from the table chosen and the field type thus narrowing down the result set.
    Now what I need to be able to do is create three dropdown JComboBox the first needs to access the database and return a list of tables to choose from, the second needs to access the database again based on the chosen table and return the unique resorts from the field, The third needs to return data from a different field in the tabe based on unique type.
    There will also be two text boxes to display the calculation result.
    The variables are currently declared and visible to other classes.
    Question: Is using a three JComboBox and two JTextBox combination with change watching the best way of acieving this?
    I dont want to spend a lot of time working out how to combine this little lot only to find out it doesn't work or there is a better way of doing this.
    Sorry for the long winded question but the last time I wrote anything it was in assembler and Java is all new to me.
    Thank you

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    I'm no pro at something like this, so you will likely want to wait for answers from smarter professional folks, but I think we can answer that doing something as you plan can be done your way, but whether it's best or not is a user interface issue, and may be best answered by creating a flexible prototype(s) and working with your user to see what they like best.

    As a caveat though (and sorry if you know already), but please be sure to do all database interactions in a thread that is background to the Swing thread such as can be achieved by using a SwingWorker object.
    Last edited by Fubarable; 04-22-2011 at 03:13 PM.

  3. #3
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Rizal Province, Philippiines
    Rep Power


    Good thing you're on the advanced stuff like java with database...
    Its not practical that you use an ordinary array to store all the query result, you can use vector that doesn't require you do declare size.
    You can create combo box then get its getText for combox.. then use it for your sql statement for your queries
    Last edited by RichersooN; 04-22-2011 at 04:53 PM.

  4. #4
    Paul_White is offline Member
    Join Date
    Apr 2011
    Rep Power

    Smile Thanks guys

    I had a sneaky suspicion I was going the wrong route.
    Thanks for your advice I will have a play and see how I get on.

Similar Threads

  1. Replies: 5
    Last Post: 03-02-2011, 10:45 PM
  2. JComboBoxes
    By Genetix in forum New To Java
    Replies: 1
    Last Post: 01-18-2010, 04:22 PM
  3. problem with JComboBoxes?
    By swayam07 in forum New To Java
    Replies: 4
    Last Post: 08-27-2008, 06:41 AM
  4. How to interconnect two JComboBoxes?
    By swayam07 in forum New To Java
    Replies: 2
    Last Post: 08-21-2008, 12:35 PM
  5. JComboBoxes
    By Keerti in forum New To Java
    Replies: 3
    Last Post: 07-28-2008, 07:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts