Forums Register Login

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

+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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.
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1126 times.
Similar Threads
addKeyListener() help needed plz
URGENT PLEASE
JSplitterView treats panes differently
How can I diplay and Applet on a swing application?
JSplitPane
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:23:27.