• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Grid layout

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
For my next trick, I'll need the help of a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic