views:

15

answers:

1

Hi, I want to know how to place JButtons at a particular coordinate in the JFrame. All day I have seen layouts. This does not suit my purpose. I would prefer something like setBounds. Rumour has it that it does not work but setLocation does. I tried it but, the program disregards the setLocation line and sets it to a Layout.


CODE


import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.BorderLayout;

public class SwingUI extends JFrame {

public SwingUI() {
    JFrame frm = new JFrame("OmegaZ");
    JButton btn = new JButton("ClickMe");
    frm.getContentPane().add(btn, BorderLayout.NORTH);
    frm.setSize(400, 400);
    frm.setVisible(true);
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    btn.setLocation(100, 200);
}

public static void main(String[] args) {

    new SwingUI();
}
}

Any help is appreciated.

Many Thanks

+1  A: 

You can do absolute positioning with a null layout. You do all the work in that case.

duffymo