import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JSplitPane; public class MainFrame extends JFrame { public MainFrame() { JSplitPane jsp1 = new JSplitPane(); jsp1.setLeftComponent(new JLabel("第一个JSplitPane的左边")); JSplitPane jsp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT); jsp2.setLeftComponent(new JLabel("第二个JSplitPane的上边")); jsp2.setRightComponent(new JLabel("第二个JSplitPane的下边")); jsp1.setRightComponent(jsp2); this.add(jsp1); this.setTitle("JSplitPane示例"); this.setSize(800, 600); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
public static void main(String[] args) { new MainFrame(); } }简单的来个例子,楼主参考!
可以用多个JSplitPane嵌套来实现啊。比如:要实现三列的。inner=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JLabel("a"), new JLabel("b")); outer=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, inner, new JLabel("c")); 效果是: a | b | c类似于用JPanel一样,多嵌套一下就可以啦
import java.awt.*; import java.awt.event.*; import javax.swing.*;public class SplitPaneFrame extends JFrame { private JButton btnLeft = new JButton("左边"); private JButton btnRightTop = new JButton("右上"); private JButton btnRightBottom = new JButton("右下");
public SplitPaneFrame() { JSplitPane rightPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, btnRightTop, btnRightBottom); JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, btnLeft, rightPane); add(pane); }
public static void main(String[] args) { JFrame frame = new SplitPaneFrame(); frame.setVisible(true); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
JSplitPane jp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT ,new JLabel("上"),new JLabel("下"));
JSplitPane tpsplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT,jp ,new JLabel("右")) ;现在就是这样的,我怎么在右测分割呢,上面的操做只直在底下分割了,
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
public class MainFrame extends JFrame {
public MainFrame() {
JSplitPane jsp1 = new JSplitPane();
jsp1.setLeftComponent(new JLabel("第一个JSplitPane的左边"));
JSplitPane jsp2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
jsp2.setLeftComponent(new JLabel("第二个JSplitPane的上边"));
jsp2.setRightComponent(new JLabel("第二个JSplitPane的下边"));
jsp1.setRightComponent(jsp2);
this.add(jsp1);
this.setTitle("JSplitPane示例");
this.setSize(800, 600);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MainFrame();
}
}简单的来个例子,楼主参考!
outer=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, inner, new JLabel("c"));
效果是: a | b | c类似于用JPanel一样,多嵌套一下就可以啦
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class SplitPaneFrame extends JFrame
{
private JButton btnLeft = new JButton("左边");
private JButton btnRightTop = new JButton("右上");
private JButton btnRightBottom = new JButton("右下");
public SplitPaneFrame()
{
JSplitPane rightPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
btnRightTop,
btnRightBottom);
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
btnLeft,
rightPane);
add(pane);
}
public static void main(String[] args)
{
JFrame frame = new SplitPaneFrame();
frame.setVisible(true);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}