• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jtable and jscrollpane question

 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JScrollPane scrollPane = new JScrollPane(yourTable);
yourTable.setPreferredScrollableViewportSize(new Dimension(int,int ));
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic