Click here to Skip to main content
12,749,285 members (36,555 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java
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();


JPanel leftPanel = new JPanel();

leftPanel.add(firstList );

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


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) {


Posted 22-Feb-13 7:47am
Updated 22-Feb-13 7:48am
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100