Start New Discussion within our Software Development Community

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();

        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.add(new ControlPanel());

Attachments Untitled2.png 51.92 KB Untitled.png 63.63 KB
This question has already been answered. Start a new discussion instead.