2013-02-27 104 views
-4

我只是无法得到这个出现我想要的方式,即时用尽试图网格布局,GridBagLayout中,的borderlayout等等的Java Swing网格布局问题

PLZ我需要帮助

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); 
+0

这很好。预计如何知道你想要达到的目标是什么? – MadProgrammer 2013-02-27 05:10:16

+0

你有没有想过可能做2个面板而不只是一个?一个带有'GridLayout(1,2)'和另一个可能是'GridLayout(6,1)'的面板?我会让你决定如何处理这些问题。 – pattmorter 2013-02-27 05:18:06

+0

我不认为我可以,我的老师并没有在图中声明2个jpanel:( – 2013-02-27 05:22:04

回答

1

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

从3个容器开始。父容器中,JScrollPane/JTable又像JPanel

  • 设置父容器布局BorderLayout东西。添加 JScrollPane/JTable它,在CENTER位置... add(scrollPane, BorderLayout.CENTER);
  • 创建一个新的JPanel,并设置它的布局GridLayout(0, 1)
  • 添加您的按钮,这个面板
  • 这个面板加入的EAST位置父容器... add(buttonPanel, BorderLayout.EAST)
+0

我编辑我的代码,以显示更多的我做了什么,我想我会问老师是否有可能添加另一个jpanel,因为它似乎是做这件事的首选方式 – 2013-02-27 05:36:57