Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to add values from a JComboBox to JTabel cells?  RSS feed

 
Rebecca Jonson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone ,
How can I add values from a JComboBox to a JTable ? I've created a drop down list and a button and I want the values to be added to a table whenever i click on the button (add).
 
Brett Spell
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three parts to what you described:

  • Detect when the button has been clicked
  • Retrieve the selected value from the combo box / drop down
  • Add the selected value to your table model.


  • Which of these do you need help with and what have you already tried?

    In any case the answer to the third item will depend on what TableModel implementation you're using, so please post the code you've already written here.
     
    Rebecca Jonson
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you so much for the reply !
    well i'm actually a beginner in java swings and JTable is also new to me however I had this thought in my head and I'm trying hard to make it but have no idea how.
    I've made a Jcombobox list with book names and there's a textfield next to it so when you choose a book its price will show on the textfield. Now what I need to do is add the value of the book name and its price to a table but i don't know how




     
    Campbell Ritchie
    Sheriff
    Posts: 53750
    127
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Not swings, please. Tables are by no means easy; I have forgotten everything I knew about tables. Try the Java Tutorials.

    And welcome to the Ranch
     
    Rob Camick
    Ranch Hand
    Posts: 2753
    11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Now what I need to do is add the value of the book name and its price to a table


    You can dynamically add rows of data to a JTable by using the addRow(...) method of the DefaultTableModel. This assumes you are using the DefaultTableModel as the TableModel for you JTable.

     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!