Home arrow static arrow Java Programming [Archive] - List Box Won't Show Up
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - List Box Won't Show Up
This topic has 2 replies on 1 page.

Posts:67
Registered: 2/8/04
List Box Won't Show Up  
Jul 11, 2004 7:16 AM



 
For some reason my list box isn't showing up. I had it showing up 15 minutes ago but now it seems to have left me. I changed everything back to what it was when I had it working but I'm still doing something wrong.

[code]
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;

public class ListTest extends JFrame {
private JList colorList;
private Container container;

// set up GUI
public ListTest()
{
super( "List Test" );

// get content pane and set its layout
container = getContentPane();
container.setLayout( new FlowLayout() );

// create a list with items in colorNames array
colorList = new JList();
colorList.setVisibleRowCount( 5 );

// do not allow multiple selections
colorList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );

// add a JScrollPane containing JList to content pane
container.add(colorList);

setSize( 350, 150 );
setVisible( true );

} // end ListTest constructor

public static void main( String args[] )
{
ListTest application = new ListTest();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}

} // end class ListTest

[/code

 

Posts:73
Registered: 7/13/03
Re: List Box Won't Show Up  
Jul 11, 2004 7:33 AM (reply 1 of 2)



 
If your JList contains no elements you have to set the size of the component. Example:
colorList.setPreferredSize(new Dimension(100,200));
 

Posts:67
Registered: 2/8/04
Re: List Box Won't Show Up  
Jul 11, 2004 8:38 AM (reply 2 of 2)



 
that did it, thanks.
 
This topic has 2 replies on 1 page.