jxmultisplitpane:如何使用? [英] jxmultisplitpane: how to use?

查看:36
本文介绍了jxmultisplitpane:如何使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一个 JXMultiSplitPane 的 javadoc 但我一无所知.我将如何使用它来显示水平排列的 5 个 JPanel,中间有分隔线?

I found a javadoc for JXMultiSplitPane 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.

请查看这段代码.代码取自 2007 年的 Swinglabs 演示文稿.加载需要一段时间,请耐心等待.

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);

我理解你的沮丧.我希望看到所有的 Swingx 网站都恢复到以前的状态,从 java.net 的 bl**dy 'crash' 开始.这么多好的项目现在很难看到.

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);
    }
}

检查他们的代码并从那里开始非常有帮助.DefaultSplitPaneModel 的代码对我非常有用.我相信你自己会设法做到的.毕竟,正如您在模型中看到的那样,这并不难.该模型可以用三行编码,但我添加了等权重功能.

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 :)

我建议您下载该库的代码、文档和 jar,并将它们捆绑到一个 NetBeans 库中.然后,每当您想查看例如他们如何对特定类进行编码时,您可以按住 CTRL 并在类名上单击鼠标,它将带您进入其实现.始终对所有开源库执行此操作.在开始时这样做可以在未来节省大量时间.如果您需要帮助,我很乐意为您提供帮助.

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.

这篇关于jxmultisplitpane:如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆