• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

GridBagLayout

 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why when I resize this frame to be of a lesser height than when packed does the textfield become extremely narrow?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
The shrinking of text field happens bcoz the layout resizes the shape of each and every component placed on it, whenever there is any change in the size of the window.
One way to resolve this problem is to use : JToolBar
Try the following code:

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.*;

public final class Temp3{

JToolBar toolBar = new JToolBar();
JTextField textField = new JTextField();
JPanel panel = null;
GridBagConstraints c = null;
public static void main(String[] args)
{
JFrame f = new JFrame("test");
f.setLayout(new GridBagLayout());
panel = new JPanel();
panel.setLayout(new GridBagLayout());
c = new GridBagConstraints();
panel.add(new JTextField(24),c);

toolBar.add(panel);
toolBar.setFloatable(false);

f.getContentPane().add(toolBar);
f.pack();
f.setVisible(true);

}
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic