• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
lyo Yashnoo
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • 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!
 
Torgil Zethson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!