How do I combine a JTextField and a JRadioButton?

I would like to have a JRadioPanel with three options. The first two are hardcoded options, and I want the third to be an 'Other' button. I would like to have a JTextField instead of text as the title of that button, but I'm not sure how to do that. I tried simply putting the field as the argument for the radio button, but it didn't like that much. I haven't found anything online to tell me how, except maybe through NetBeans, and that doesn't do me much good. Is there any way to easily do this, or will I have to do some fancy stuff with the layout?

Okay, new problem. The buttons are all looking right, but for some reason they're in a row instead of in a column. Here's the code for it. Not sure why it's doing this.

    tf2 = new JTextField("Other", 20);
    newName.setActionCommand("newname");
    fulfillment.setActionCommand("fulfillment");
    fulfillment.setSelected(true);
    type.add(fulfillment);
    type.add(newName);
    fulfillment.addActionListener(this);
    newName.addActionListener(this);
    GridBagConstraints rC = new GridBagConstraints();
    JPanel radioPanel3 = new JPanel(new GridBagLayout());
    rC.gridwidth = 2;
    radioPanel3.add(fulfillment);
    rC.gridy = 1;
    radioPanel3.add(newName);
    rC.gridy = 2;
    rC.gridwidth = 1;
    radioPanel3.add(other);
    rC.gridx = 1;
    radioPanel3.add(tf2);
    c.gridx = 10;
    c.gridy = 4;
    pane.add(radioPanel3, c);

Answers


Place the third radiobutton without text and add JTextField. E.g. Use GridBagLayout where the first and the second radiobuttons take 2 columns and in the third row the "empty" radiobutton has row=2 col=0 and JTextField row=2 col=1


Need Your Help

How to limit result set size for arbitrary query in Ingres?

sql oracle ingres

In Oracle, the number of rows returned in an arbitrary query can be limited by filtering on the "virtual" rownum column. Consider the following example, which will return, at most, 10 rows.

show/hide div on mouseover not working

javascript jquery html css delegates

I have the following code and i want when the user moves the mouse over the div it will display and when the mouse moves out of div it will hide. Every thing seems ok but it is not working . can an...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.