1

I have some problem , i want my jpanel to look like this enter image description here but after codING i had this view and i didnt find the solution , enter image description here i need some helps please.

i put the radio button inside jScrollPan //listmateriel is a list (vector) of radio button ---------- //imagebox is jpanel contains jradio buttons and the image ---------

//gridlayoutPanel2 is Jpanel contains the two text fields and jlabel and a JComboBox

package tpjava;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
i.......


public class Frame extends JFrame implements ActionListener  {
    private static final int  Haut = 550;
    private static final int Larg = 720;
    private final JPanel utilisateur;
    private final JButton recherche;
    private final JRadioButton radioButton,radioButton2;
    private Vector listmateriel;
    private final JLabel label;

    public Frame()
    {
         super("Gestion des materiels");
         setSize(Larg,Haut);
         setResizable(false);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         JTabbedPane menu = new JTabbedPane();








          JPanel emprunt = new JPanel();
         emprunt.setPreferredSize(new Dimension(Larg, Haut ));
         emprunt.setLayout(new BoxLayout(emprunt, BoxLayout.Y_AXIS));
         emprunt.setBorder(BorderFactory.createEmptyBorder(20,20, 20, 20));


         JPanel emp1 = new JPanel();
         emp1.setPreferredSize(new Dimension(Larg-40, 200 ));
         emp1.setLayout(new BorderLayout());


         JLabel title2 = new JLabel("Nouvel emprunt:");
         title2.setBorder(BorderFactory.createEmptyBorder(20,20,0,0));


         JPanel box2 = new JPanel();
         box2.setPreferredSize(new Dimension(Larg, 40 ));
         box2.setLayout(new BoxLayout(box2, BoxLayout.X_AXIS));
         box2.add(title2);
         box2.add(Box.createHorizontalStrut(650));
         emprunt.add(box2);



         JLabel label3 = new JLabel("test");
         JButton dispo = new JButton("Disponibilité");
         dispo.addActionListener((ActionListener) this);
         dispo.setPreferredSize(new Dimension(200, 30));

         JPanel box1 = new JPanel();
         box1.setLayout(new BoxLayout(box1, BoxLayout.X_AXIS));
         box1.add(dispo);
         box1.add(Box.createHorizontalStrut(450));
         box1.add(label3);
         emp1.add(box1,BorderLayout.SOUTH);




        listmateriel = new Vector();
         for(int k =0 ;k <10 ; k++)
              listmateriel .add(new JRadioButton(res.getString("nom"+k)));


       ......

        ImageIcon newIcon = new ImageIcon(bi);
        JLabel picture = new JLabel(newIcon);
        picture.setBorder(BorderFactory.createEmptyBorder(0,450,0,0));


        JPanel jplRadio = new JPanel();
        jplRadio.setLayout(new GridLayout(0, 1));

        for(int i = 0 ; i < listmateriel.size() ;i++)
        {  
            jplRadio.add((Component) listmateriel.elementAt(i));

          }



        JPanel imagebox = new JPanel();
        imagebox.setLayout(new BorderLayout());
        JScrollPane scroll3 = new JScrollPane(jplRadio);
         scroll3.setPreferredSize(new Dimension(200, 30));

        imagebox.add(scroll3, BorderLayout.WEST);
        imagebox.add(picture, BorderLayout.CENTER);
        emp1.add(imagebox,BorderLayout.CENTER);

         JPanel box3 = new JPanel();
         box3.setLayout(new BoxLayout(box3, BoxLayout.X_AXIS));
         JLabel title3 = new JLabel("Remplir les champs suivants:");
         box3.add(title3);
         box3.add(Box.createHorizontalStrut(650));



         JPanel gridlayoutPanel2 = new JPanel();

            ........

             JPanel util5 = new JPanel();
            util5.setLayout(new GridLayout(0,1));
            util5.setBorder(BorderFactory.createLineBorder(Color.black));

           JLabel resul2 = new JLabel("bsfgbsdg");      
           JScrollPane scroll2 = new JScrollPane();

           util5.add(resul2);

         emprunt.add(emp1);
         emprunt.add(box3);
         emprunt.add(gridlayoutPanel2);
         emprunt.add(util5);


         menu.add("emprunts",emprunt);

         //---------------------
         getContentPane().add(menu);
         pack();
         setVisible(true);

    }


}
Malek Djelassi
  • 85
  • 1
  • 10
  • 2
    Can you place up the complete working code. I tried to paste this into a Java form and I had a mess. – Doug Hauf May 23 '14 at 22:05
  • 2
    Please edit your question to include an [short, complete example](http://stackoverflow.com/help/mcve) that focuses on the problem; instead of `BoxLayout`, try `GridLayout(0, 1)`. – trashgod May 23 '14 at 22:05
  • @DougHauf the code have some server-side part , so it may not work in ur IDE , u can replace "listmateriel" by some single jradiobutton – Malek Djelassi May 23 '14 at 22:30
  • 1
    *"the code have some server-side part"* So it is obviously irrelevant to a layout problem. Remove it. *"u can replace"* 1) Spell words like 'you' properly. These are not text messages. 2) If *you* could not be bothered replacing it, we should ***we***? – Andrew Thompson May 24 '14 at 02:20
  • 1
    i just removed the server-side part and replaced by simple jradiobuttons – Malek Djelassi May 24 '14 at 08:33

1 Answers1

2

GridLayout(0, 1) instead of BoxLayout is the solution thank you @trashgod

Malek Djelassi
  • 85
  • 1
  • 10