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 6179651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:42:26+00:00 2026-05-24T00:42:26+00:00

I have got a window that looks like window1 and I would like it

  • 0

I have got a window that looks like window1 and I would like it to look like window2:

enter image description here

This is my code:

    String q = "Have you used GUI before?";     
    JLabel textLabel2 = new JLabel(
        "<html><div style=\"text-align: center;\">" + q + "</html>", SwingConstants.CENTER);
    add(textLabel2, BorderLayout.NORTH);

    JPanel radioPanel = new JPanel();                                           
    add(radioPanel, BorderLayout.CENTER);

    JPanel btnPanel = new JPanel();
    add(btnPanel, BorderLayout.SOUTH);

For the radio-buttons, I tried to use GridLayout, but it broke the position of “Yes” and “No”. And for the “back” and “next” buttons, horizontal alignment did not work (btnPanel.setAlignmentX(RIGHT_ALIGNMENT);), apparently. Any solutions will be highly appreciated, I’m stuck with this bit way too long. Thanks

–EDIT–
That is working perfectly fine:

btnPanel.setLayout(new BoxLayout(btnPanel, BoxLayout.LINE_AXIS));
btnPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
btnPanel.add(Box.createHorizontalGlue());

so the buttons problem is solved.
However, still can’t get the radio-buttons fixed.

–EDIT 2–
Fixed the background for the radio-buttons using setOpaque(false);

  • 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-05-24T00:42:27+00:00Added an answer on May 24, 2026 at 12:42 am

    What do you mean by it “broke” the position of “yes” and “no” as a GridLayout should work just fine. I’d give it 1 column and 2 (or 0 for variable number of) rows via new GridLayout(0, 1). Be sure that its opaque property is set as false by doing radioPanel.setOpaque(false);. This way it will show the background color of the container that it sits in. You may need to make the JRadioButtons non-opaque as well, I’m not sure.

    Your btnPanel could use a BoxLayout and use Box.createGlue() to push the buttons over to the right side.

    Most importantly — if you haven’t yet done so, please read the tutorials on use of the Swing layout managers which you can find here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a series of filepaths that look something like this: C:\Windows\System32\svchost.exe -k LocalSystemNetworkRestricted
I have a URL that looks like http://mysite.com/#id/Blah-blah-blah , it's used for Ajax-ey bits.
I have got some code to load an assembly and get all types, which
I have got the following code from here to read an Excel file using
I have got this error when using Enterprise Library 3.1 May 2007 version. We
Say I have a method like this: public void SaveData() { try { foreach
We have got a custom MembershipProvider in ASP.NET . Now there are 2 possible
We have got loads of options for php + MySQL + Apache combo... Which
I have got a python script which is creating an ODBC connection. The ODBC
I have got a C function in a static library, let's call it A,

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.