From: "Singh,Gary - PLANO" <[EMAIL PROTECTED]>
Cc: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
Date: Wed, 24 Oct 2001 11:04:39 -0500
set the weightx property of GridBagConstraints as 0 this is will not strech
the component in cell
Did you try this? When I tried it, the unwanted resizings still
occurred (code below).
Moreover, even if this solution had worked, I suspect it would have
supressed all resizing, even those that are wanted, such as when the
user resizes the application window. This would be particularly
problematic when instead of a button, the component with varying
contents is, say, a JScrollPane containing a JTextArea (which the user
may want to enlarge).
KJ
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
public class Sick2 extends JPanel {
private static JFrame frame;
private JScrollPane scrollPane;
private JPanel panel;
private JTree tree;
private JButton button;
private GridBagLayout gbl;
private JList list;
private final String LONG_LABEL = "v e r y l o n g";
private final String SHORT_LABEL = "short";
public Sick2() {
super();
gbl = new GridBagLayout();
setLayout(gbl);
GridBagConstraints gbc;
tree = new JTree
(new DefaultTreeModel(new DefaultMutableTreeNode("Minimal tree")));
scrollPane = new JScrollPane(tree);
scrollPane.setMinimumSize(scrollPane.getPreferredSize());
gbc = getBaseConstraints();
gbc.gridx = 0; gbc.gridy = 0;
gbc.weightx = 1.;
add(scrollPane, gbc);
button = new JButton(LONG_LABEL);
button.addActionListener(new MyButtonListener());
panel = new JPanel();
panel.add(button);
gbc = getBaseConstraints();
gbc.gridx = 1; gbc.gridy = 0;
gbc.weightx = 0.;
add(panel, gbc);
}
private GridBagConstraints getBaseConstraints() {
GridBagConstraints baseGbc = new GridBagConstraints();
baseGbc.weightx = baseGbc.weighty = 1.;
baseGbc.fill = GridBagConstraints.BOTH;
return baseGbc;
}
private class MyButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String text = button.getText();
if(text.equals(LONG_LABEL)) {
button.setText(SHORT_LABEL);
}
else {
button.setText(LONG_LABEL);
}
}
}
public static void main(String[] args) {
frame = new JFrame();
frame.getContentPane().add(new Sick2(), "Center");
frame.pack();
frame.show();
}
}
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing