• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to add a JButton to SplitPaneDivider? (why it can't work?)

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends:

In a JApplet, I want to add a JButton to SplitPaneDivider.But the code seem's don't work property. My code is:

////////////// TestApplet extends JApplet ////////////////
public class TestApplet extends JApplet {
public void paint(Graphics g) {
JPanel f=new JPanel();
f.setPreferredSize(new Dimension(300,200));

f.setBackground(Color.green);
f.setVisible(true);
f.setLayout(new BorderLayout());

JButton jep=new JButton("b");
JSplitPane jspcontent=new JSplitPane(JSplitPane.VERTICAL_SPLIT,f,jep);
jspcontent.setOneTouchExpandable(true);
jspcontent.setDividerSize(50);

BasicSplitPaneUI bspUI=(BasicSplitPaneUI)jspcontent.getUI();
JButton b=new JButton("test");
b.setVisible(true);
BasicSplitPaneDivider divi=bspUI.getDivider();

divi.add(b);
divi.setVisible(true);
divi.validate();

this.setContentPane(jspcontent);
this.setVisible(true);
this.validate();
}
}
///////////// end //////////////////

The divider can't display the JButton, why?

But in a frame (None JApplet ) application, it can work property. Does the JApplet can't use BasicSplitPaneDivider ?
:roll:

Thks!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look at the source code for BasicSplitPaneDivider you will see that the divider uses its own, custom layout manager. That layout manager simply ignores anything you add to the divider; it just lays out a fixed set of components that it knows about, namely the left and right button you get by default when you make the splitpane one-touch expandable.

So you will either have to provide your own layout manager, or override the BasicSplitPaneDivider class itself to acchieve what you want.
 
reply
    Bookmark Topic Watch Topic
  • New Topic