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 have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I've got two dataframes that look like this: ==fileA LmjF.01 257506 257508 1 LmjF.01
I have got a window that should display the following: JLablel Have you used
I have a URL that looks like http://mysite.com/#id/Blah-blah-blah , it's used for Ajax-ey bits.
vb.net windows forms question. I've got 3 forms that have exactly the same functions,
if i have got 1 Window and in the interface builder i add a
I've got a WPF window where I have a column of buttons on the
This question about Timers for windows services got me thinking: Say I have (and
Can anyone shed any light on this? I feel like I have wasted the
I've got an issue involving a website that I have been using VS 2008

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.