• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jtable and jscrollpane question

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic