• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

format JList

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
change the selection mode to ListSelection.MULTIPLE_SELECTION.
 
I've been selected to go to the moon! All thanks to this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic