Closed. This question needs to be more focused。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
                        
                        4年前关闭。
                                                                                            
                
        
我希望这样进行申请:

------------------------------
|         Toolbar            |
------------------------------
|              |             |
|              |             |
|              |-------------|
|              |             |
|              |             |
------------------------------


哪个布局管理器适合于此屏幕链接?

最佳答案

我建议GroupLayout。一旦习惯了,没有什么能为您提供控制GroupLayout大小的控件类型。您可以使用如下形式:

import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.border.BevelBorder;

public class LayoutFrame extends JFrame {
  private JPanel contentPane;
  private JMenuBar menuBar;

  public LayoutFrame() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    // Create the toolbar
    menuBar = new JMenuBar();
    menuBar.add(new JMenu("File"));
    setJMenuBar(menuBar);

    setSize(500, 500);

    contentPane = new JPanel();
    GroupLayout layout = new GroupLayout(contentPane);
    contentPane.setLayout(layout);
    setContentPane(contentPane);

    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);

    // Create the panels for the different regions
    JPanel leftPanel = new JPanel();
    leftPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
    JPanel topRightPanel = new JPanel();
    topRightPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
    JPanel bottomRightPanel = new JPanel();
    bottomRightPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));

    // Create a sequential group for the horizontal axis.
    GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
    hGroup.addComponent(leftPanel);
    hGroup.addGroup(layout.createParallelGroup().
             addComponent(topRightPanel).addComponent(bottomRightPanel));
    layout.setHorizontalGroup(hGroup);

    // Create a parallel group for the vertical axis.
    GroupLayout.ParallelGroup vGroup = layout.createParallelGroup();
    vGroup.addComponent(leftPanel);
    vGroup.addGroup(layout.createSequentialGroup().
             addComponent(topRightPanel).addComponent(bottomRightPanel));
    layout.setVerticalGroup(vGroup);
  }

  public static void main(String[] args) {
    final LayoutFrame frame = new LayoutFrame();
    EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        frame.setVisible(true);
      }
    });
  }
}


这将创建此框架(Ubuntu Unity)。您应该能够弄清楚如何自行调整差距。

java - 哪些布局管理器可以制作面板式GUI?-LMLPHP

并具有自动间隔:

java - 哪些布局管理器可以制作面板式GUI?-LMLPHP

关于java - 哪些布局管理器可以制作面板式GUI? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32322706/

10-12 05:01