*
The moose likes Swing / AWT / SWT and the fly likes jtable and jscrollpane question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jtable and jscrollpane question" Watch "jtable and jscrollpane question" New topic
Author

jtable and jscrollpane question

jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
hey,

I have a JTable in a JScrollPane. My application is designed to have this table take up most of the screen. Sometimes the table has hundreds of rows of data in it and everything works well.

However, sometimes it only has three rows in it and it looks very bad inside of the scrollPane.

I would like my table to be full screen all the time regardless of the actual number of rows of data it has.

Is there an easy way to do this or do I have to add "blank" rows to my table whenever I detect this condition?
Joe Myn
Greenhorn

Joined: Oct 19, 2004
Posts: 25
JScrollPane scrollPane = new JScrollPane(yourTable);
yourTable.setPreferredScrollableViewportSize(new Dimension(int,int ));
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
Thanks for the reply but it doesn't seem to have the affect I was looking for.

Take a look at this code:



This frame should fill the screen, but the table will only have six rows in it.

Is it possible to fill the rest of the table with some "blank" rows somehow?
Mikie Williams
Greenhorn

Joined: Jan 11, 2005
Posts: 7
try commenting out
table.setPreferredScrollableViewportSize(new Dimension(900, 900));
and
pack();

Then add setExtendedState(JFrame.MAXIMIZED_BOTH) right under
super("Table example, Wines from Bordeaux").

See if that helps. One note. I believe you have to be using a jdk of 1.4.0 or higher though.
jefff willis
Ranch Hand

Joined: Sep 29, 2004
Posts: 113
No, that seemed to be a step back.

It didn't solve the problem and I had to stretch the frame when my application initially loaded.

I guess I'm just going to have to fake this in the program...I just figured that there would be an easy way around this.
Mikie Williams
Greenhorn

Joined: Jan 11, 2005
Posts: 7
so your program looks like this and it didn't work. Well I am sorry. It maximizes the window when I run it.

public class MyClass extends JFrame {
public MyClass() {
super("Table example, Wines from Bordeaux");
setExtendedState(JFrame.MAXIMIZED_BOTH);
Object[][] tabledata = {
{ "Chateau Meyney, St. Estephe", new Integer(1994), "$18.75" },
{ "Chateau Montrose, St. Estephe", new Integer(1975), "$54.25" },
{ "Chateau Gloria, St. Julien", new Integer(1993), "$22.99" },
{ "Chateau Beychevelle, St. Julien", new Integer(1970), "$61.63" },
{ "Chateau La Tour de Mons, Margeaux", new Integer(1975), "$57.03" },
{ "Chateau Brane-Cantenac, Margeaux", new Integer(1978),
"$49.92" }, };
String columnheaders[] = { "Wine", "Vintage", "Price" };
JTable table = new JTable(tabledata, columnheaders);
//table.setPreferredScrollableViewportSize(new Dimension(900, 900));
JScrollPane scrollPane = new JScrollPane(table);
getContentPane().add(scrollPane);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
//pack();
}

public static void main(String[] args) {
MyClass mc = new MyClass();
mc.show();
//mc.setVisible(true);
}
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jtable and jscrollpane question
 
Similar Threads
JTable
JTABLE
JTable
JTable
JTable Paging