1 Replies - 703 Views - Last Post: 18 September 2012 - 07:34 AM Rate Topic: -----

#1 redhat69  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 30
  • Joined: 28-June 12

Moving GUI Buttons

Posted 17 September 2012 - 09:00 PM

I am trying to set up an intererface and want to movie this one ok button it really doesn't matter where to right now I just started learning. But i cannot seem to get it to move from the center of my frame no matter what. Any hints?
 */
package program_3;


import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Joe
 */
public class Program_3 extends JPanel {

  JButton okButton;
  GridBagConstraints c = new GridBagConstraints();
  
    /**
     *
     */
    public Program_3 ()
   {
   setLayout(new GridBagLayout());
   
   okButton = new JButton(" Ok ");
   c.gridx = 0;
   c.gridy = 0;
   add(okButton,c);
   
   
       
   }
    public static void main(String[] args) {
        JFrame Frame = new JFrame();
        Program_3 Go = new Program_3();
        Frame.setTitle("Program 3");
        Frame.setSize(500,500);
        Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Frame.setVisible(true);
        Frame.add(Go);
        
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Moving GUI Buttons

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 8,802
  • Joined: 20-September 08

Re: Moving GUI Buttons

Posted 18 September 2012 - 07:34 AM

Why use a GridBagLayout? If you don't care where it moves to, use FlowLayout (the default)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1