Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Horizontal List Box and JScrollPane

Posted on 2003-11-24
7
Medium Priority
?
255 Views
Last Modified: 2010-03-31
I have an array of Integers, which I want to display on my Panel HORRIZONTALLY(if there is such a word!). I want a Scrollbar under this list to allow the user to move across a list, and select an item. I want to add action listeners on the list which will reflect selection of an item.
 What should I use? The array  will have fixed 200 elements. I tried using JScrollPane with a listbox, but didn't know if that was the right way to go.

I have to figure this out asap.
0
Comment
Question by:miteshn
  • 5
  • 2
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9814545
Use a JTable with a single row.
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 9814555
DefaultTabelModel model = new DefaultTableModel(1, 200);
for (int i=0; i<200; i++)
{
   model.setValueAt(new Integer(values[i]), 0, i);
}
JTable table = new JTable(model);
JScrollPane scroller = new JScrollPane(table);
0
 
LVL 92

Expert Comment

by:objects
ID: 9814575
Use a ListSelectionListener to listen for user selections.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:miteshn
ID: 9814790
this is the code i use: -

public JTable getlayerTabel(){
      layerTableModel = new DefaultTableModel(1,200);
      for(int i=0;i<200;i++){
            layerTableModel.setValueAt(new Integer(i),0,i);
      }
      JTable layerTable = new JTable(layerTableModel);
      layerTable.setBounds(5,25,45,35);
      JScrollPane layerScrollPane = new JScrollPane(layerTable);
      layerScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      return layerTable;
      }

But, in my display, i am not getting any slider on the ScrollBar. Also, is the default color of the scrollpanel white?
thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 9814806
> layerTable.setBounds(5,25,45,35);

why do u do this?

> return layerTable;

Why aren't you returning your scroll pane?
You should be adding the scroll pane to your component hierarchy, not the table.

>  Also, is the default color of the scrollpanel white?

not sure of the top of my head. U can change it if need be.
0
 

Author Comment

by:miteshn
ID: 9816440
>> layerTable.setBounds(5,25,45,35);

>why do u do this?

i am doing this 'cuz i am using a null layout on my plane....

thanks for ur help
0
 
LVL 92

Expert Comment

by:objects
ID: 9816449
No worries :-)

http://www.objects.com.au
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question