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);
# 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.
# 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.
# 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);
}
}
#