jxmultisplitpane: how to use?
I found a javadoc for JXM开发者_Python百科ultiSplitPane but I'm clueless. How would I use this to display 5 JPanels lined up horizontally with splitters in between?
It doesn't answer your question exactly but I hope it is helpful.
Please check out this piece of code. The code was taken from the swinglabs presentation from 2007. It takes a while to load so be patient.
//Simple case: creates a split pane with three
//compartments
JXMultiSplitPane sp = new JXMultiSplitPane();
sp.setModel(new DefaultSplitPaneModel());
sp.add(left, DefaultSplitPaneModel.LEFT);
sp.add(top, DefaultSplitPaneModel.TOP);
sp.add(bottom, DefaultSplitPaneModel.BOTTOM);
EDIT: I understand your frustrations. I would like to see all the website of swingx returning to its previous state, from before the bl**dy 'crash' of the java.net. So many nice projects are now so hard to view.
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.jdesktop.swingx.JXMultiSplitPane;
import org.jdesktop.swingx.MultiSplitLayout.Divider;
import org.jdesktop.swingx.MultiSplitLayout.Leaf;
import org.jdesktop.swingx.MultiSplitLayout.Split;
public class JXMultiSplitPaneTest extends JPanel
{
private static final long serialVersionUID = 1L;
public JXMultiSplitPaneTest()
{
//Simple case: creates a split pane with three compartments
JXMultiSplitPane sp = new JXMultiSplitPane();
JPanel p1 = new JPanel();
p1.setBackground(Color.PINK);
JPanel p2 = new JPanel();
p2.setBackground(Color.YELLOW);
JPanel p3 = new JPanel();
p3.setBackground(Color.CYAN);
JPanel p4 = new JPanel();
p4.setBackground(Color.RED);
JPanel p5 = new JPanel();
p5.setBackground(Color.BLUE);
sp.setModel(new FiveHorizontalSplitPaneModel(true));
sp.add(p1, FiveHorizontalSplitPaneModel.P1);
sp.add(p2, FiveHorizontalSplitPaneModel.P2);
sp.add(p3, FiveHorizontalSplitPaneModel.P3);
sp.add(p4, FiveHorizontalSplitPaneModel.P4);
sp.add(p5, FiveHorizontalSplitPaneModel.P5);
setLayout(new BorderLayout());
add(sp);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
JXMultiSplitPaneTest p = new JXMultiSplitPaneTest();
JFrame f = new JFrame();
f.setContentPane(p);
f.setSize(800, 600);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
});
}
}
class FiveHorizontalSplitPaneModel extends Split
{
//5 possible positions
public static final String P1 = "1";
public static final String P2 = "2";
public static final String P3 = "3";
public static final String P4 = "4";
public static final String P5 = "5";
public FiveHorizontalSplitPaneModel()
{
this(false);
}
public FiveHorizontalSplitPaneModel(boolean isEqualyWeighted)
{
setRowLayout(true);
Leaf p1 = new Leaf(P1);
Leaf p2 = new Leaf(P2);
Leaf p3 = new Leaf(P3);
Leaf p4 = new Leaf(P4);
Leaf p5 = new Leaf(P5);
if(isEqualyWeighted)
{
p1.setWeight(0.2);
p2.setWeight(0.2);
p3.setWeight(0.2);
p4.setWeight(0.2);
p5.setWeight(0.2);
}
setChildren(p1, new Divider(), p2, new Divider(),
p3, new Divider(), p4, new Divider(), p5);
}
}
It is very helpful to check their code out and go from there. Very useful for me was the code for the DefaultSplitPaneModel. I believe you would have managed to do it yourself. It wasn't that hard after all as you can see in the model. The model could be coded in three lines but I have added the equal weighting feature.
Pleasure to help. Have fun :)
I would suggest you download the code, the documentation and jar for that library and have them bundled together into a NetBeans library. Then whenever you want to see, for example, how they have coded a particular class you hold the CTRL
and click the mouse on the class name and it will take you to its implementation. Do so always for all open source libraries. Doing so at start saves lots of time in the future. If you need a hand with that I am happy to help.
精彩评论