Adding ScrollPane to Table

Hi all,

I am Doing project in Java Swing. I need a help line for using scroll pane with table and textarea.

final String[] colheads={"Book Name","Due Date"};

final Object[][] data={{"",""},{"",""},{"",""},{"",""},{"",""},{"",""}};

JTable table=new JTable(data,colheads);

JScrollPane jsp=new JScrollPane(table);//,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

panel.add(jsp);

getContentPane().add(panel);

[1433 byte] By [SridharJavaa] at [2007-11-26 18:48:25]
# 1
What kind of help do you need?
duckbilla at 2007-7-9 6:22:25 > top of Java-index,Desktop,Core GUI APIs...
# 2

final String[] colheads={"Book Name","Due Date"};

final Object[][] data={{"",""},{"",""},{"",""},{"",""},{"",""},{"",""}};

JTable table=new JTable(data,colheads);

JScrollPane jsp=new JScrollPane(table);//,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

panel.add(jsp);

getContentPane().add(panel);

Actually the above won't work well.

SridharJavaa at 2007-7-9 6:22:25 > top of Java-index,Desktop,Core GUI APIs...
# 3
>Actually the above won't work well.So what is wrong with it? Try adding the scrollpane directly to the contentpane.
duckbilla at 2007-7-9 6:22:25 > top of Java-index,Desktop,Core GUI APIs...
# 4
Actually I have the same problem - the following code doesn't put vertical or horizontal scrolls in my jtable.
nofearinca at 2007-7-9 6:22:25 > top of Java-index,Desktop,Core GUI APIs...
# 5
@nofearincIf you want the scrollbars to be always visible, use thisnew JScrollPane(Component, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);#
duckbilla at 2007-7-9 6:22:25 > top of Java-index,Desktop,Core GUI APIs...
# 6

Seems like this is going to work now - scrolls are visible, but the contents from the JList/JTable I'm using is hidden - as the JScrollPane overlays it. Any idea how I can set it to visible?

What I do is

-create JList and fill it

-create JScrollPane and add the JList into it

-add the JSCrollPane in my frame

I suppose that there are problems in the bounds of my components.

nofearinca at 2007-7-9 6:22:25 > top of Java-index,Desktop,Core GUI APIs...
# 7

Well I can't really say without seeing any code, but try this

package testing;

import javax.swing.*;

public class Test

{

public static void main(String[] args)

{

JFrame frame = new JFrame("Test");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

String[] data = {"Ankka", "Possu", "Sorsa", "Nakki"};

JList list = new JList(data);

JScrollPane scroller = new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

frame.add(scroller);

frame.pack();

frame.setVisible(true);

}

}

#

duckbilla at 2007-7-9 6:22:26 > top of Java-index,Desktop,Core GUI APIs...
# 8
I executed your code and there was a visible scroll pane. I changed my GUI utilities, but without effect - I'm almost sure that it's a bounds or layout problem. Thanks for the example :)
nofearinca at 2007-7-9 6:22:26 > top of Java-index,Desktop,Core GUI APIs...