• Post Reply Bookmark Topic Watch Topic
  • New Topic

Grid layout  RSS feed

 
Roopa Joshi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sachin pathak
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!