-4

我只是无法让它以我想要的方式出现,我已经筋疲力尽地尝试 gridlayout、gridbaglayout、borderlayout 等......

请问我需要帮助

在此处输入图像描述

这就是我到目前为止所做的

    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);
4

1 回答 1

1

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

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

  • 将父容器布局设置为BorderLayout. 将 JScrollPane/添加JTable到它的CENTER位置...add(scrollPane, BorderLayout.CENTER);
  • 创建一个新JPanel的并将其布局设置为GridLayout(0, 1)
  • 将按钮添加到此面板
  • 将此面板添加到EAST父容器的位置...add(buttonPanel, BorderLayout.EAST)
于 2013-02-27T05:20:53.427 回答