简体   繁体   English

添加一个在 JSplitpane 和 JPanel 之间拆分的 JScrollpane?

[英]Add a JScrollpane that split between JSplitpane and JPanel?

I'm just trying to insert a scrollpane, but I'm not going to get it.我只是想插入一个滚动窗格,但我不会得到它。 I have 3 areas defined by a panel.我有 3 个由面板定义的区域。 The left area to the middle is separated by a splitpane.中间的左侧区域由分割窗格分隔。 The middle area is separated by a scrollpane.中间区域由滚动窗格分隔。 Well clear vertical from top to bottom.从上到下垂直清晰。 I hope you can help me because I am currently really frustrated and no answer to my solution.我希望你能帮助我,因为我目前真的很沮丧,我的解决方案没有答案。

Here is a Picture which shows what my goal is to create.这是一张图片,显示了我的目标是创造什么。

在此处输入图片说明

In this Method we define the split and return this to the JFrame.在此方法中,我们定义拆分并将其返回给 JFrame。

 public JSplitPane defineSplit() {
    JPanel leftPanel = leftArea();
    JPanel centerPanel = middleArea();
    JPanel rightPanel = rightArea();
    JSplitPane splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, centerPanel);
    JSplitPane splitPane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitPane1,rightPanel);
    splitPane1.setVisible(true);
    splitPane2.setVisible(true);
    return splitPane2;
}

Here is my Method which creates the content and return the Information to defineSplit().这是我的方法,它创建内容并将信息返回给defineSplit()。

public JPanel leftArea() {
    JPanel panel = new JPanel(new FlowLayout());
    panel.add(new JLabel("left area"));
    return panel;
}

public JPanel middleArea() {
    JPanel panel = new JPanel(new FlowLayout());
    panel.add(new JLabel("middle area"));
    return panel;
}

public JPanel rightArea() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
    panel.add(new Label("right area"));
    return panel;
}

The last one is my Frame.最后一个是我的框架。 My frame is in a extra class.我的框架是在一个额外的类。 Here you can just see the method.在这里你可以看到方法。

public void createFrame() {
    setJMenuBar(AnimeMenuBar.getInstance().createMenu(this));
    setTitle("Anime");
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setPreferredSize(new Dimension(1000, 500));
    JSplitPane splitPane = content.defineSplit();
    add(splitPane);
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
}

defineSplit() method: defineSplit() 方法:

public JSplitPane defineSplit() {
    JPanel leftPanel = leftArea();
    JScrollPane centerScrollPane = middleArea();
    JPanel rightPanel = rightArea();
    JSplitPane splitPane1 = new JSplitPane();
    JSplitPane splitPane2 = new JSplitPane();

    splitPane1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    splitPane1.setRightComponent(splitPane2);
    splitPane1.setLeftComponent(leftPanel);
    splitPane2.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    splitPane2.setRightComponent(rightPanel);
    splitPane2.setLeftComponent(centerPanel);

    return splitPane1;
}

middleArea() method: middleArea() 方法:

public JScrollPane middleArea() {
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    return scrollPane;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM