Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java GUI Discussions 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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 10th, 2005, 05:07 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display

Hello everybody :)!

Somebody can help me?

I have the following code.

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);


    frame.pack();
    frame.setVisible(true);



  }
}

Thanks.


Reply With Quote
  #2 (permalink)  
Old May 10th, 2005, 04:52 PM
Authorized User
 
Join Date: Dec 2004
Location: karachi, , Pakistan.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello

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);


    frame.pack();
    frame.setVisible(true);



  }
}

ok take care

HumaMunir
Reply With Quote
  #3 (permalink)  
Old May 11th, 2005, 02:23 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help this prgm run without error now.

but I try to apply this on my main pgm and I cann't.

The question is:
I want to add various panels to one frame but I get only the last one. How I can display this three panels together?

 my code is like this: I show you the sket :

public class PP extends JFrame
{
        public PP {

        JPanel panel = new JPanel();
        getContentPane().add(panel);

        JLabel titleLabel = new JLabel(title);

        panel.add(titleLabel);

        start();

        initComponents ();
    .......
  }

    private void start() {


      JPanel panel1 = new JPanel();
      getContentPane().add(panel1);
    .......

}
              private void initComponents() {

          JPanel panel2 = new JPanel();
         getContentPane().add(panel2);
        .......
}

        .... }
}


Thanks in advance.
Reply With Quote
  #4 (permalink)  
Old May 11th, 2005, 03:54 AM
Authorized User
 
Join Date: Dec 2004
Location: karachi, , Pakistan.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yeah its ok :)
so what is the problem in it. i think the panels are overlapped why dont you try for layout manager like

getContentPane().add(panel,BorderLayout.NORTH);

try it, otherwise send me the errors it shows.

take care

HumaMunir
Reply With Quote
  #5 (permalink)  
Old May 12th, 2005, 02:31 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello!!

Thanks again for your help!
I resolved my pb by adding

getContentPane().setLayout(new GridBagLayout()); first.
then:

getContentPane().add(panel,c); for each panel:D

JavaLö.
Reply With Quote
  #6 (permalink)  
Old May 12th, 2005, 12:29 PM
Authorized User
 
Join Date: Dec 2004
Location: karachi, , Pakistan.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

good:)

HumaMunir
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
display annumol Hibernate 1 March 21st, 2008 03:43 PM
Picture display Venkatesan General .NET 2 January 31st, 2007 07:27 AM
display.asp jstewie Javascript How-To 0 August 18th, 2005 07:43 AM
Display Data. mistry_bhavin ADO.NET 2 May 4th, 2004 09:22 AM
can't display syounger JSP Basics 3 February 12th, 2004 06:46 AM



All times are GMT -4. The time now is 01:23 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.