Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2005, 05:07 AM
Registered User
 
Join Date: May 2005
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.


 
Old May 10th, 2005, 04:52 PM
Authorized User
 
Join Date: Dec 2004
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
 
Old May 11th, 2005, 02:23 AM
Registered User
 
Join Date: May 2005
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.
 
Old May 11th, 2005, 03:54 AM
Authorized User
 
Join Date: Dec 2004
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
 
Old May 12th, 2005, 02:31 AM
Registered User
 
Join Date: May 2005
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ö.
 
Old May 12th, 2005, 12:29 PM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

good:)

HumaMunir





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 08: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 07:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.