aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes JTable size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JTable size" Watch "JTable size" New topic
Author

JTable size

Charley Zuo
Greenhorn

Joined: Jan 10, 2002
Posts: 4
Hi,
My Client class extends JFram and I set dimension as:
setSize(new Dimension(1000,600));
And for JTable I set dimension as:
table.setPreferredScrollableViewportSize(new Dimension(1000, 400));
It works fine on my machine. But today I tried it on another machine and the JTable only occupied about 70% of the width of the frame. Also I noticed that some field with big width can not be displayed completely. But once I ever resize the window the JTable expands to the same size as the JFrame.
Does anybody have any experience on this?
Many thanks.
Charley
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Charley,
What kind of layout manager are you using? Are you wrapping your JTable in a JScrollPane? There are a lot of factors that determine why a JTable reacts on a resize. Also you might consider using pack() on your JFrame instead of setting a fixed size. You could also get some control by listening to WindowEvents and controling behaviour there although it's generally easier to do that by the proper choice of layout managers.
Hope this helps
Michael Morris
SCJP


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
amit ahuja
Ranch Hand

Joined: Nov 20, 2001
Posts: 38
please help me too in JTable. you look like a savior to me..
I have used default table model and JTable and i found that ENTER key is for moving the selection down in the Jtable By default. I wanted to use enter as click to default button. But it seems i'm not able to override (or disable)the default function of enter.
I tried objectMap & inputMap and couple of such things... but nothing helped.. please help me..
thanks
amit
Rajesh Matti
Ranch Hand

Joined: Jan 07, 2002
Posts: 121
Amit- I think the enter key behaviour is perfectly all right as it is the default behaviour Sun has provided. If you still want to change it, I think , table.registerKeyboardAction() is the way to go. (I am not sure though).
ActionListener enterAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
//whatever you wanna do
};
};

table.registerKeyboardAction(downAction,
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
JComponent.WHEN_FOCUSED);
Let me know.
Thanks
-Rajesh
Charley Zuo
Greenhorn

Joined: Jan 10, 2002
Posts: 4
Hi Machael,
Many thanks for your reply and the pack() method solved my problem.
Just for your information that I use BoarderLayout for JFrame and I didn't wrap JTable in a JScrollPane.
Thanks again.
Charley
amit ahuja
Ranch Hand

Joined: Nov 20, 2001
Posts: 38
Rajesh sorry for delay,
Actually i tried that method before and that didn't help me.
Any more ideas.. it is LAST hoodUp in my assignement.. waiting on it.
Thanks
amit
Rajesh Matti
Ranch Hand

Joined: Jan 07, 2002
Posts: 121
Amith- The following code works for me, I do not know what is happening in your code, so this is all I can do.

import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.*;
public class TestJTable {
public TestJTable() {
super();
}
public static void main(java.lang.String[] args) {
String[] columnNames = { "COL1", "COL2" };
String[][] data = { { "Data_1", "Data_2" }, {
"Data_3", "Data_4" }, {
"Data_5", "Data_6" }
};
final JFrame frame = new JFrame("JTABLE TEST");
JTable table = new JTable(data, columnNames);
ActionListener enterAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame, "ENTER KEY PRESSED");
};
};
table.registerKeyboardAction(
enterAction,
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
JComponent.WHEN_FOCUSED);
JScrollPane scrollPane = new JScrollPane(table);
frame.getContentPane().add(scrollPane);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable size