Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JTable isEditable Property and Table Listener

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

All this time I am only using one ( possibly the easiest / simplest ) approach to fill up a GUI Builder created JTable Column Headers and Data, because that just fit my needs.

here is my code :



but Now this isnt enough, because I couldn't change the Table's Cell Editable Property.

I tried several ways of achieving it, without the need to change how I create my table and get the data much, but its not working.

I tried this, it kind worked ( with a blank / null row ), but when I tried to fill up the row data using the getData() as mentioned above, it failed.



What I am trying to Achieve is to Make only Column(6) Editable , the Rest should not be Editable.


and I dont know if this should be on a separate Thread or not.

But I am also trying to Figure out  on How to Tell the Table to recalculate Column Total  as soon as the User Finished Editing a cell on New_Bill ( I dont have any idea which event I should use ).

as the User finished Editing on a Cell on Column New_Bill then the Table will get Value from Column Old_Bill add it with the New Value from Column New_Bill and it will be the New Value of Column Total.

and Again, I am sorry if its hard to understand, I am doing my best with my English limitation.

Thank you.
 
Saloon Keeper
Posts: 8943
76
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Added this to the Swing forum.



I apologize, and Thank you.
 
Rancher
Posts: 3253
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't try to initialize the data with an empty 2D array. The DefaultTableModel has many constructors you can use.

I would do something like the following to create an model with no data:



Now whenever you want to load new data into the model you can do:



And to add new rows of data I would use a Vector:


for two reasons:

1. no need to worry about indexes
2. the DefaultModel copies the Array to a Vector anyway, so creating the Vector saves creation of a temporary Array.


How to Tell the Table to recalculate Column Total  as soon as the User Finished Editing a cell on New_Bill



If the "Column Total" is part of the table then you can override the setValutAt(...) method of the TableModel. Whenever a value in the column is changed you reset the total.

If the "Column Total" is external to the table, then you can add a TableModelListener to the TableModel. You will receive an event any time data is changed in the model. For an example of this approach see: https://coderanch.com/t/516824/java/jtable-combo-box
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#Rob Camick"

Thnks a lot, I'll Try that.

for now I use an an InputMessage everytime a user click on New_Bill row, then they need to input the new value of it, after the user clicked OK on the inputMessage, all the needed columns of the selected row will update its value ( though still would be better to do it without an inputMessage pane).

and to remind users not to change the value of the other columns I use an OptionPane, for now, once I get to understand your suggestion I'll change everything to the proper way.

and my Work Laptop is so slow, so does the internet here, I am trying my best to respond here when I get the chance.
 
reply
    Bookmark Topic Watch Topic
  • New Topic