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.
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.
Use a JTable with a single row.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use a ListSelectionListener to listen for user selections.
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.setHorizon talScrollB arPolicy(J ScrollPane .HORIZONTA L_SCROLLBA R_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
public JTable getlayerTabel(){
layerTableModel = new DefaultTableModel(1,200);
for(int i=0;i<200;i++){
layerTableModel.setValueAt
}
JTable layerTable = new JTable(layerTableModel);
layerTable.setBounds(5,25,
JScrollPane layerScrollPane = new JScrollPane(layerTable);
layerScrollPane.setHorizon
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.
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.
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
>why do u do this?
i am doing this 'cuz i am using a null layout on my plane....
thanks for ur help