Java GUIDiscussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
After running the program,I don´t obtain all the components which I want to insert(label, txt and t2).
I obtain only the last component"t2".Help!
import javax.swing.*;
public class test2
{
public static void main(String[] args)
{
JLabel label = new JLabel("A Very Simple Text Label");
JRadioButton txt = new JRadioButton("t1",false);
JRadioButton t1 = new JRadioButton("t2",false);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.getContentPane().add(label); // adds to CENTER
frame.getContentPane().add(txt);
frame.getContentPane().add(t1);
i think this is because the components are overlapped so you can add them by using any layout like this
import javax.swing.*;
import java.awt.*;
public class test2
{
public static void main(String[] args)
{
JLabel label = new JLabel("A Very Simple Text Label");
JRadioButton txt = new JRadioButton("t1",false);
JRadioButton t1 = new JRadioButton("t2",false);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.getContentPane().add(label,BorderLayout.NORT H); // adds to CENTER
frame.getContentPane().add(txt,BorderLayout.CENTER );
frame.getContentPane().add(t1,BorderLayout.SOUTH);