This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Grid layout

 
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
 
Bartender
Posts: 9615
16
Mac OS X Linux 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.
 
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
 
Seriously Rick? Seriously? You might as well just read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic