• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to add values from a JComboBox to JTabel cells?

 
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
    Marshal
    Posts: 52590
    119
    • 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: 2701
    10
    • 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.

     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!