Solved

Horizontal List Box and JScrollPane

Posted on 2003-11-24
7
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven module vs maven project 3 115
Java: The Public Class Main 4 65
Eclipse Java import and method not resolved 4 130
wild fly 8 startup error 2 79
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
This video teaches viewers about errors in exception handling.
Suggested Courses

734 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