Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when the applet runs add, at first the Jlist on the right is barely visible, but after adding elements to the list the center buttons resize taking up almost the entire space leaving a small space for both JLists.
Vector vector = new Vector()

JButton add = new JButton("add");

JButton remove = new JButton("remove");

DefaultListModel model =new DefaultListModel();

JList firstList = new JList(vector);

Jlist selectedList = new Jlist(model);


JPanel rightPanel = new JPanel();

rightPanel.add(selectedList);

JPanel leftPanel = new JPanel();

leftPanel.add(firstList );

JPanel centerButtons = new JPanel(new GridLayout(2,1);

centerButtons.add(add);
centerButtons.add(remove);

add.addActionListener(new ButtonListener());
remove.addActionlistener(new RemoveButton());

setLayout(new BorderLayout());

add(rightPanel, BorderLayout.EAST);
add(leftPanel, BorderLayout.WEST);
add(centerButtons, BorderLayout.CENTER);

     private class ButtonListener implements ActionListener
      {
        public void actionPerformed(ActionEvent e) {


                model.addElement(firstList.getSelectedValue());
           
          

        }
Posted
Updated 22-Feb-13 6:48am
v2
Comments
nameJulian 16-May-13 5:42am    
I believe that your problem might be the GridLayout for your centerButtons panel. GridLayout tells the program, that the buttons can ocupy all the space they can aquire. Try using this:

JPanel centerButtons=new JPanel();
centerButtons.setLayout9(new BoxLayout(centerButtons,BoxLayout.Y_AXIS);

This is much like GridLayout(2,1). It display's the buttons vertical in the Panel.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900