Hello. I am trying to move my button to the topmost part of my application's window.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class test extends JFrame{ public test() { super("A window"); setSize(500,500); setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); JPanel panel=new JPanel(); JButton button=new JButton("Hey my name is bob"); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints=new GridBagConstraints(); constraints.gridwidth=10; constraints.gridheight=10; constraints.gridx=0; constraints.gridy=0; constraints.fill=GridBagConstraints.BOTH; panel.add(button,constraints); add(panel); setVisible(true); } public static void main(String[] s) { test a=new test(); } }
I read the java sun tuts on gridbaglayout but I am still struggling as far as learning how to place controls.Can someone tell me how to position componenets on a gridbaglayout pane the exact way i want them to be layed out?