when to call setBounds(), setLocation(), ...
- From: Kova <kova1337@xxxxxxxxxxxxxxx>
- Date: Thu, 27 Apr 2006 13:31:09 +0200
Hello.
I'm using BoxLayout and I can't get components to show as I want. I create components, do setBounds on them, make everything visible and it dosen't work! It only works if I set bounds after I show them (make them visible).. why? Of course I want to set where the components will be displayed first and then display them, not display them and then move them around... help? Below is example of the problem.
-------------------------------------------------------
import java.awt.Dimension;
import javax.swing.*;
public class TFrame extends JFrame {
JTextField tf1 = new JTextField("Test 1");
public TFrame() {
super("TEST");
setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
setDefaultCloseOperation(EXIT_ON_CLOSE);
tf1.setBounds(50,50,200,75); // dosen't work
tf1.setMaximumSize(new Dimension(200,75));
add(tf1);
setBounds(0,0,400,200);
setVisible(true);
// tf1.setBounds(175,50,200,75); // this works
}
public static void main(String[] args) {
new TFrame();
System.out.println("Tnx a lot comp.lang.java.gui! :)");
}
} // end of class
------------------------------------------------
.
- Follow-Ups:
- Re: when to call setBounds(), setLocation(), ...
- From: Thomas Weidenfeller
- Re: when to call setBounds(), setLocation(), ...
- From: moumita
- Re: when to call setBounds(), setLocation(), ...
- Prev by Date: Re: Execution problem with jhotdraw
- Next by Date: using non-standard fonts
- Previous by thread: JOptionPane focus
- Next by thread: Re: when to call setBounds(), setLocation(), ...
- Index(es):