Re: Place JComponent in center of JDialog. Solved
- From: "Martijn Mulder" <i@m>
- Date: Wed, 29 Jun 2005 21:17:55 +0200
Thank you Knute for this terse example that I had
little trouble compiling. I straightened it out a little,
(kicked out the thread) and hope that someone Googling
on 'component+center+parent' will find it someday
//How to place a component in the center of its parent
//Original code by Knute Johnson
//Adapted for the millions by Martijn Mulder
//One class test3 is all it takes
public class test3
{
//One method main is all it takes
public static void main(String[] args)
{
//create JPanel, paint it blue, set preferred size
javax.swing.JPanel p=new javax.swing.JPanel();
p.setBackground(java.awt.Color.blue);
p.setPreferredSize(new java.awt.Dimension(400,300));
//create JFrame, set Layout manager, add JPanel + GridBagConstraints
javax.swing.JFrame f=new javax.swing.JFrame();
f.getContentPane().setLayout(new java.awt.GridBagLayout());
f.getContentPane().add(p,new java.awt.GridBagConstraints());
f.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
}
.
- Follow-Ups:
- Re: Place JComponent in center of JDialog. Solved
- From: Knute Johnson
- Re: Place JComponent in center of JDialog. Solved
- References:
- Place JComponent in center of JDialog
- From: Martijn Mulder
- Re: Place JComponent in center of JDialog
- From: Knute Johnson
- Place JComponent in center of JDialog
- Prev by Date: How to make default font w/ metal Laf using Synth
- Next by Date: Re: How to make default font w/ metal Laf using Synth
- Previous by thread: Re: Place JComponent in center of JDialog
- Next by thread: Re: Place JComponent in center of JDialog. Solved
- Index(es):