Solved

Horizontal List Box and JScrollPane

Posted on 2003-11-24
7
250 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 500 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
couple of eclipse 5 46
javap not working 8 58
SequenceInputStream example 3 19
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

839 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