Forums Register Login

Grid layout

+Pie Number of slices to send: Send
I have an applet, where i am showing status of some elements. I am using grid layout with six rows. If user clicks on any of the row, I have to show the same layout with two more button added to it in the row where the user has clicked.
Is there any way of knowing in which row user has clicked.
Thanks in advance
+Pie Number of slices to send: Send
What are you displaying in your applet? If the 6 items are JButtons, you could call setActionCommand() on each of them with a String representation of the row. If you are displaying JLabels (or any other subclass of Component) you could add a MouseListener to each, though I would think you would have to subclass the component to have a data member to indicate the row. You could also do away with the GridLayout and use a JList to display your selections. Then you could implement ListSelectionListener somewhere and have the selection delivered to you in a ListSelectionEvent.
+Pie Number of slices to send: Send
 

Originally posted by Roopa Joshi:
I have an applet, where i am showing status of some elements. I am using grid layout with six rows. If user clicks on any of the row, I have to show the same layout with two more button added to it in the row where the user has clicked.
Is there any way of knowing in which row user has clicked.
Thanks in advance


The best way is to do away with the layout and Use a JTable control to display the widgets. You can get the row number and column number from the Tables model when it is clicked.
Do not get bogged down by the complexity of te JTAble, actually it is very easy to use.
Sachin
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1014 times.
Similar Threads
what layouts to use
Newbie Swing Question
using jbutton to change New objects
Update based on Row id
Buttons without clicking animation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:56:01.