Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

format JList

 
sae0203
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i set the size of the display list?
and how can i make it display 3 choices at a time?
Below is my current code:

//items in thr list box

listModel = new DefaultListModel();
listModel.addElement("---ALL---");
//to display the products
for(int i=1; i<=9; i++)
{listModel.addElement("Product " + i);}
//Create the list and put it in a scroll pane
list = new JList(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//set the Visible number of item that a user can view at a glance
list.setVisibleRowCount(3);
//Set the font of the items display
Font displayFont = new Font("Serif", Font.BOLD, 12);
list.setFont(displayFont);
//set the default selected item
list.setSelectedIndex(0);
//list.addListSelectionListener(this);
list.setLength(20);
JScrollPane listScrollPane = new JScrollPane(list);
so is there a code like
list.setSize(20); :roll:
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ambrosia 0203" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

There is a setSize() method, but it doesn't do what you want... look into setVisibleRowCount( int ) instead...

Thanks! and welcome to the JavaRanch!
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change the selection mode to ListSelection.MULTIPLE_SELECTION.
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!