• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic