• 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

Selecting JPanels

 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm creating a "market" kinda like what you might find in a video game, e.g you can buy swords, potions, etc.
I'm laying it out as follows. There is a JInternalFrame which contains a JTabbedPane. The JTabbedPane contains a different JPanel for each category; obviously only one JPanel/category can be seen at a time. Within each JPanel is a JScrollPane containing a scrollable JPanel. That inner JPanel is using a VerticleFlowLayout to display ProductPanels (which simply extend JPanels).
In short, you can flip between scrollable lists of JPanels. I want to let the user click on one of my ProductPanels (efectively JPanels) and be able to figure out which JPanel was clicked on. I'm not quite sure how to do this. Any ideas?
--Mark
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can call getParent() on any Component to get a reference to the Container it's in, so code can call getParent() on a ProductPanel and simply chain the calls upward until they hit one of those category panels. If we propose a CategoryPanel class, then all you have to do is
 
Mark Herschberg
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, I don't follow.
I already know who the panel's parent is. I want to know, when the user clicks on a panel, which panel it clicked on. Is there some way to capture the mouse click and figure out in what panel it was (without using glass panes)? I also don't want to place a button in the panel and require the user to click on that, I'd rather that they can click anywhere on the panel.
--Mark
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I don't seem to be doing very well in understanding people's questions today. I thought you wanted to know which category panel the clicked ProductPanel was inside of.
Just add a mouse listener to ProductPanel; when you click on a ProductPanel, that method will be invoked, no matter how many containers it's nested inside of. It will be invoked on the actual ProductPanel object that was clicked; now if you need to figure out the category, you can add the code I showed previously into the event handler.
 
Mark Herschberg
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course, a mouse listener! Duh!
Thanks. :-p

--Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic