Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:25:29+00:00 2026-06-14T10:25:29+00:00

I am trying to align the RadioButtons in my program here. Can someonee help

  • 0

I am trying to align the RadioButtons in my program here. Can someonee help me? I am not exactly sure how to go about it. I have searched here and elsewhere and cannnot seem to find an applicable example. Here is, what I believe the relevant portion of my code. If more is needed, I will edit.

final class SplitPanel extends JFrame {
    private FlowLayout flowLayout = new FlowLayout();
    private GridLayout gridLayout = new GridLayout(4, 1);
    private DiagLayout diagLayout = new DiagLayout();

    private JRadioButton jrbFlowLayout = new JRadioButton("Horizontal");
    private JRadioButton jrbGridLayout = new JRadioButton("Verticle");
    private JRadioButton jrbDiagLayout = new JRadioButton("Diagonal");

    private JButton jbt1 = new JButton("Button 1");
    private JButton jbt2 = new JButton("Button 2");
    private JButton jbt3 = new JButton("Button 3");
    private JButton jbt4 = new JButton("Button 4");

    private JSplitPane jSplitPane;
    private JPanel jPanel1, jPanel2;

    public SplitPanel() {
        this.setTitle("Split Panel with Diagonalization");
        this.setSize(600, 400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        createPanel1();
        createPanel2();

        jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                jPanel1, jPanel2);
        jSplitPane.setOneTouchExpandable(true);
        jSplitPane.setContinuousLayout(true);
        jSplitPane.setDividerLocation(150);

        getContentPane().add(jSplitPane);
    }

    public void createPanel1() {
        jPanel1 = new JPanel();
        jPanel1.setBorder(new TitledBorder("Select a Layout Manger"));
        jPanel1.add(jrbFlowLayout);
        jPanel1.add(jrbGridLayout);
        jPanel1.add(jrbDiagLayout);

        ButtonGroup buttonGroup1 = new ButtonGroup();
        buttonGroup1.add(jrbFlowLayout);
        buttonGroup1.add(jrbGridLayout);
        buttonGroup1.add(jrbDiagLayout);

    }

    public void createPanel2() {
        jPanel2 = new JPanel();
        jPanel2.setLayout(diagLayout);
        jPanel2.add(jbt1);
        jPanel2.add(jbt2);
        jPanel2.add(jbt3);
        jPanel2.add(jbt4);

        jrbFlowLayout.addActionListener (new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jPanel2.setLayout(flowLayout);
                jPanel2.validate();
            }
        });

        jrbGridLayout.addActionListener (new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jPanel2.setLayout(gridLayout);
                jPanel2.validate();
            }
        });

        jrbDiagLayout.addActionListener (new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jPanel2.setLayout(diagLayout);
                jPanel2.validate();
            }
        });

    }

Thank you for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:25:30+00:00Added an answer on June 14, 2026 at 10:25 am

    The default layout of a JPanel is a FlowLayout.
    http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html

    You might want to set the panels layout to a GridLayout or even a BoxLayout.

    in

    createPanel1(){
    // create panel.
    jPanel1.setLayout(new GridLayout(0,1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to align an entire label along with text to the
I am trying to center align my google chart but have been unsuccessful in
I have a small problem. I am trying to align two divs side by
I'm trying to align a div horizontally, but for some reason it's not working
I am trying to align the following equations around the equal sign. What can
I am trying to align some divs a certain way. To help debug what's
I am trying to align two images horizontally using CSS. In CSS, I have:
I'm trying to align a series of images together in matlab. I have a
I am trying to align 2 JPanles in a big panel. I am not
I'm trying to align an HTML button exactly at the centre of the page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.