Link to home
Start Free TrialLog in
Avatar of miteshn
miteshn

asked on

Horizontal List Box and JScrollPane

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.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Use a JTable with a single row.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use a ListSelectionListener to listen for user selections.
Avatar of miteshn
miteshn

ASKER

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
> 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.
Avatar of miteshn

ASKER

>> 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