Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Without layout manager, we position components using absolute values

import javax.swing.JButton; import javax.swing.JFrame; public class Absolute {   public static void main(String[] args) {     JFrame f = new JFrame();     f.setLayout(null);     JButton ok = new JButton("OK");     ok.setBounds(50, 150, 80, 25);     JButton close = new JButton("Close");     close.setBounds(150, 150, 80, 25);     f.add(ok);     f.add(close);     f.setSize(300, 250);     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     f.setVisible(true);   } }