Mihai Xulescu

Greenhorn
+ Follow
since Jul 02, 2019
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 Mihai Xulescu

Carey Brown wrote:** Remove component from panel BEFORE removing it from the list.

[Edit] I still agree that using a JTable enclosed  in a JScrollPanel is the way to go.




ok noted. Since I am learning I will try to apply this and come back (for sure) when I will be stuck again. Will update. Don't close the thread please.

I like it because it is hard!
2 weeks ago

Campbell Ritchie wrote:You are lucky to get that code to compile at all. You can add a panel to a display but not a List<JPanel>, and you cannot cast a List to a panel.
Where did you initialise those Lists? Are you declaring those Lists as fields; it may be possible for them to be local variables and reduce the size of your object.



Let me clarify.

1. I am having one JPanel. Inside this JPanel I have an array of JLabel and JTextField. When I click "add" I want it to add JLabels or JTextFields into these two Arrays. When I click "remove", I want them to be removed in the same way they were added (from last to first).
So I have created two arrays as underneath:


And then I added the actionListeners as underneath (code is not working now):



My questions are added there in the comment side. Thanks,
2 weeks ago

Fred Kleinschmidt wrote:

By using lists it will solve my issue?

Well, yes. As it stands, in your action listener, you remove "label1" and "field1". The next time you click the button, you try to remove the same items that you have already removed. Those variables do not magically get reassigned to other items.



ok...I tried and it gives me this error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException



2 weeks ago

Carey Brown wrote:Instead of
You need to keep track of all of the rows




I didn't study yet Lists...I am still at arrays and next will be arraylists....

By using lists it will solve my issue?
2 weeks ago
Hi guys. I am new to this forum, curently studying java swing and creating a small application that I need at work. For the sake of simplification, when I implement new features I tend to create simple programs where I add one feature at a time, thus observing what is happening.
Overall I am creating a table in swing and I will add several textfields and labels. User will add data there and then click save. This data will eventually be saved in some arrays and then...well there is a long way to there.
So I created a right click popup menu and when I click "add row" it will add some rows. In this example one jlabel and one jtextfield. All ok until now. But I don't know how many rows my users will insert, it can be anything from 5 to 50 so I allow user to add until 50 (feature not yet implemented in this example underneath, no worries).

I add rows, it works, I delete rows...and here the problem. The last component gets deleted. But what if user wants to delete two rows? It does not work apparently. If I add 5 rows, eachof 1 label and 1 jtextfield, the remove row only deletes the last row but not also one more or as many as user keeps hitting the "remove row" button. What is wrong with my code?





Thanks guys, wish you well!
2 weeks ago