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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:24:09+00:00 2026-05-19T15:24:09+00:00

Say I wanted to add a JComboBox (or more general a JPanel , perhaps?)

  • 0

Say I wanted to add a JComboBox (or more general a JPanel, perhaps?) to a JRadioButton, what would be the easiest way to do it?

Pseudo-wise, a radio button group where one of them includes multiple choices would look something like:

O The weather
O Parties
O {meta, pseudo}-science
O Animals

where the {} would be a dropdown list. The trick here is that if one clicks either the dropdown list or the label ‘-science’ the radio button would be actived and showing the UI border and all of that fancy stuff.

Thanks 🙂

  • 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-19T15:24:09+00:00Added an answer on May 19, 2026 at 3:24 pm

    I hate giving answers like this, but in this case I feel it is best…

    This seems like a very non-standard UI component. It would be much better UX if you just did:

    O The weather
    O Parties
    O meta-science
    O pseudo-science
    O Animals
    

    Users will not be familiar with the type of component you are proposing, and it is very inconsistent with the other options in the list. I highly recommend using a more standard convention.


    Against my better judgement, I present you with ComboBoxRadioButton:
    It is not complete, nor do I suggest using it, but it looks like what you want.

    import java.awt.FlowLayout;
    
    import javax.swing.AbstractButton;
    import javax.swing.ButtonGroup;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JToggleButton;
    
    public class ComboBoxRadioButton extends JRadioButton {
    
        private JLabel beforeText, afterText;
        private JComboBox comboBox;
    
        public ComboBoxRadioButton(String beforeTxt, JComboBox comboBox, 
                                                 String afterText) {
            this.comboBox = comboBox;
            this.beforeText = new JLabel("    " + beforeTxt);
            this.afterText = new JLabel(afterText);
            comboBox.setSelectedIndex(0);
            setLayout(new FlowLayout());
            setModel(new JToggleButton.ToggleButtonModel());
            add(this.beforeText);
            add(this.comboBox);
            add(this.afterText);
        }
    
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel mainPane = new JPanel();
            ButtonGroup group = new ButtonGroup();
            AbstractButton b2 = new JRadioButton("Java Swing");
            AbstractButton b3 = new ComboBoxRadioButton(
                    "It's gonna be a", new JComboBox(new String[] { "good", "bad",
                    "rainy" }), "day!");
            AbstractButton b4 = new JRadioButton("After the combo");
            group.add(b2);
            group.add(b3);
            group.add(b4);
            mainPane.add(b2);
            mainPane.add(b3);
            mainPane.add(b4);
            f.add(mainPane);
            f.pack();
            f.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there way to override jQuery's core functions ? Say I wanted to add
Is there way to override jQuery's core functions ? Say I wanted to add
Lets say i wanted to add another variable to the database can anybody tell
Say I wanted to write a program that would export calendar data so that
If I wanted to add, let's say, a new .lib to the build only
How would you add a constant number, say 1, to a value in a
say i had a list where i wanted to add name and age so
Say I wanted to add some imports to the file generated when I run:
Say I wanted to have one variable in a class always be in some
Say I wanted to list buttons so that the last one was anchored to

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.