Solved

Horizontal List Box and JScrollPane

Posted on 2003-11-24
7
244 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
Comment Utility
Use a JTable with a single row.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
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
Comment Utility
Use a ListSelectionListener to listen for user selections.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:miteshn
Comment Utility
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
Comment Utility
> 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
Comment Utility
>> 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
Comment Utility
No worries :-)

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
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 …

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now