• Post Reply Bookmark Topic Watch Topic
  • New Topic

need to draw JButton such that it displays on top of two different panels  RSS feed

 
manasa manogna
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends

Need a help with one of the java swing challenge I am facing. Problem statement: there are two JPanels panel 1 and panel 2 placed on a JFrame one below the other as panel 2 below panel 1. Now, I need to put a JButton in any one of the panels such that this JButton displays half in panel 1 and half in panel 2. Please help me how I can do this?

Thanks
Hemanth
 
Brian Cole
Author
Ranch Hand
Posts: 947
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is IMHO a dumb challenge. Being able to do it would demonstrate a familiarity with layout, I guess, but I don't think any employer would ever want you to actually place a button on two JPanels like this. It would be better to redesign it with a single panel that would contain everything panel1 contains, everything panel2 contains, and the button.

But how to do it? Pretty much all the existing layout managers will place the button entirely in the panel it is managing, so you probably want to turn of the layout manager and set location manually. In general, this is not a good thing to do. It's possible you may also have to mess with clipping regions.

EDIT: Another approach that could work would be to use OverlayLayout on the parent of panel1 and panel2. In this case the button would belong to neither panel1 nor panel2, but to a third container.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more approach: have two buttons sharing the same model and perjure layouts to display half of each button in each panel.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!