Java Swing gridLayout问题

时间:2013-02-27 05:09:21

标签: java swing layout-manager grid-layout

我只是不能让它以我想要的方式出现,我已经筋疲力尽了尝试gridlayout,gridbaglayout,borderlayout等......

我需要帮助

enter image description here

这是我到目前为止所做的事情

    panneauEst = new JPanel(new BorderLayout());

    zoneTexte = new JTextArea("LIVRES", 45, 50);
    scroller= new JScrollPane(zoneTexte);
    scroller.setPreferredSize(new Dimension(600, 580));
    scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    EcouteurBoutons btnEcouteur = new EcouteurBoutons();

    btnTrierCote = new JButton("Trier par cote");
    btnTrierCote.addActionListener(btnEcouteur);
    btnTrierTitre = new JButton("Trier par titre");
    btnRechercheCote = new JButton("Rechercher par cote");
    btnRechercheTitre = new JButton("Rechercher par titre");
    btnFusion = new JButton("Fusion");
    btnQuitter = new JButton("Quitter");

    panneauEst.add(scroller);

    //http://stackoverflow.com/questions/15104630/java-swing-gridlayout-issue
    this.setLayout(new GridLayout(6, 2));
    this.add(panneauEst);
    this.add(btnTrierCote);
    this.add(btnTrierTitre);
    this.add(btnRechercheCote);
    this.add(btnRechercheTitre);
    this.add(btnFusion);
    this.add(btnQuitter);

1 个答案:

答案 0 :(得分:1)

您需要使用复合容器/布局

从3个容器开始。父容器,JScrollPane / JTable和类似JPanel

的容器
  • 将父容器布局设置为BorderLayout。添加 JScrollPane / JTable CENTER位于add(scrollPane, BorderLayout.CENTER);位置JPanel
  • 创建新的GridLayout(0, 1)并将其布局设置为EAST
  • 将您的按钮添加到此面板
  • 将此面板添加到父容器的add(buttonPanel, BorderLayout.EAST)位置... {{1}}
相关问题