Win a copy of Head First Android this week in the Android forum!

Andrea Marasco

Greenhorn
+ Follow
since Jul 15, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andrea Marasco

I guess you're right.

So if I want to use a single TableCellRenderer for every cell in the JTable and still use correctly the model-view-controller pattern then I would adopt a solution like this (this is just an example):



Now I'm just storing a String in the TableModel and that String is inside a class that tells the renderer to render that String inside a JButton.

This should be the correct way, isn't that? And what about my non-functioning program? And then, do I have to mark this thread as solved since I've solved my problem?
8 years ago
I've solved my problem by using a MouseListener and then firing the event whenever I click on buttons (I don't know if I have to mark this thread as solved); however I'd like to talk more about this argument.

Ranganathan Kaliyur Mannar wrote:
A model should hold data and not GUI components. Renderers and Editors then dictate on how that data is used.



I know about the model-view-controller design pattern, the thing is that a JTable is a GUI component so I don't think it is that bad that the model contains GUI components. Also I think that the rendering/behavior of the components should be responsibility of the components not of the JTables, that's why I have put those JButton in the components and then I basically told the cell editor/renderer: "Whenever you encounter a JButton just let him express the way he wants".

Ranganathan Kaliyur Mannar wrote:
You have provided some code, but we are unable to deduce the issue from the same. I would suggest that you write a small runnable program which replicates the issue and paste the same. This is called SSCCE. This makes it easier for fellow ranchers to simply copy your code and run it rightaway - and that means they can see the issue and provide suggestions.



Ok then, here's a full example:



Try to create 5 buttons and then delete the third row (the one with the index 2); you will see that this example is deleting the fourth row and not the third one.
8 years ago
Hi everyone

Here is my problem: I have a JTable with some data in it and a JButton in the last column of the TableModel (for each row).

When you click on this JButton, other than the perfectly working application logic, I want it to become disabled (setEnabled(false);) and to have a certain text within it.

This is perfectly working. The problem enters when I have more than one row: if there is another enabled JButton in the next row to this disabled JButton and the row with the disabled JButton gets removed (tableModel.removeRow(someIndex);) then the someIndex+1 row is moved to the someIndex row BUT the new JButton that was supposed to be enabled stays disabled!

Here's what I mean:

Before removing the first row:


After removing the first row:


I want that JButton, after the row removal, to be enabled. How can I overcome to this problem?

Here it is some of my code:



Thanks to everyone that will help me in advance :-)
8 years ago