Hello Guys,

Im Using GridbagLayout as LayoutManager, but I am not able to place my button at top-right of my frame.

I'm also attaching my current output and what i actually want to do.

here's my code:

package projectilemotion;

/**
 *
 * @author Taimoor
 */

import javax.swing.*;
import java.awt.*;

public class ControlPanel extends JPanel {

    public JRadioButton position, velocity, acceleration, energy;
    public JTextField heightTextField, velocityTextField, angleTextField;
    private JLabel initialHeight, initialVelocity, initialAngle;
    private ButtonGroup bg;
    private JButton start;

    public ControlPanel()
    {
        setLayout(new GridBagLayout());
        start = new JButton("Start");

        initialHeight = new JLabel("Initial Height");
        initialVelocity = new JLabel("Initial Velocity");
        initialAngle = new JLabel("Initial Angle");

        heightTextField = new JTextField(2);
        velocityTextField = new JTextField(2);
        angleTextField = new JTextField(2);

        position = new JRadioButton("Display Position");
        velocity = new JRadioButton("Display Velocity");
        acceleration = new JRadioButton("Display Acceleration");
        energy = new JRadioButton("Display Energy");
        bg = new ButtonGroup();
        bg.add(position);
        bg.add(velocity);
        bg.add(acceleration);
        bg.add(energy);

        GridBagConstraints a = new GridBagConstraints();

        a.insets = new Insets(10,10,10,10);
        a.weightx = 4;
        add(start, a);   

    }
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setSize(1000,600);
        frame.add(new ControlPanel());
        frame.setVisible(true);
    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.