代码之家  ›  专栏  ›  技术社区  ›  Daniel Del Core

Java Swing拆分窗格视图布局

  •  3
  • Daniel Del Core  · 技术社区  · 13 年前

    你好,我正在实现我的第一个拆分窗格视图,它似乎对我不起作用,我得到了以下输出。。。

    enter image description here

    这是代码。

    //Create Album Panel
        albumPanel.setLayout(new FlowLayout());
    
        //Add List view
        albumList.setMinimumSize (new Dimension(150,150));
        albumPanel.add(new JScrollPane(albumList));
    
    
        //Add Text Area
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setEditable(false);
        textArea.setMinimumSize (new Dimension(150,150));
        albumPanel.add(textArea);
    
        //Split Pane
        JSplitPane splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, albumList, textArea);
    
        albumPanel.add(splitpane, BorderLayout.CENTER);
    
    2 回复  |  直到 13 年前
        1
  •  2
  •   David Kroukamp    13 年前

    您已设置 albumPanel 布局到 FlowLayout 但你试着用 BorderLayout 添加到 JSplitPane 以下为:

    albumPanel.add(splitpane, BorderLayout.CENTER);

    你应该设置 白蛋白面板 布局到 边界布局 通过 new BorderLayout()

    此外,将组件的大小设置为 LayoutManager 让我们为你做这件事。

        2
  •  2
  •   Hovercraft Full Of Eels    13 年前

    您需要将包含列表和文本区域的组件JScrollPane添加到JSplitPane中,以便它显示它们。是的,正如David所说(对他来说是1+),容纳JSplitPane的容器需要能够让它展开,BorderLayout可以很好地实现这一点。

    此外,不要多次向容器中添加组件。将组件添加到JScrollPane,然后将JScrollpane添加到JSplitPane。不要同时将组件添加到albumPanel容器中。你的代码在这方面有点精神分裂。