Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2692 > unrolled thread

JLebel as a container

Started by"Chanchal" <chanchal@THRWHITE.remove-dii-this>
First post2011-04-27 15:40 +0000
Last post2011-04-27 15:40 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.gui


Contents

  JLebel as a container "Chanchal" <chanchal@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000
    Re: JLebel as a container "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000

#2692 — JLebel as a container

From"Chanchal" <chanchal@THRWHITE.remove-dii-this>
Date2011-04-27 15:40 +0000
SubjectJLebel as a container
Message-ID<1193388915.336894.268240@d55g2000hsg.googlegroups.com>
  To: comp.lang.java.gui
Hi All,

I'm trying to add a JLable 'jLable2 to another JLabel 'jLabel1'. But
jLabel2 is not getting displayed.

My code is

import javax.swing.*;

public class LabelTest extends JFrame {

    public LabelTest(){
 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        JLabel jLabel1 = new javax.swing.JLabel();
        jLabel1.setText("jLabel1");
        JLabel jLabel2 = new JLabel();
        jLabel2.setText(" TEXT ");
        jLabel1.add(jLabel2);
        getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);
        pack();
    }


    public static void main(String args[]) {
	LabelTest lTest = new LabelTest ();
	lTest.setSize(400,300);
	lTest.setVisible(true);
    }

}

Please advice on how i can make jLabel2 visible.
Thanks in advance

Chanchal

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#2693

From"Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Date2011-04-27 15:40 +0000
Message-ID<7a42e8aa4e8ca@uwe>
In reply to#2692
  To: comp.lang.java.gui
Chanchal wrote:
..
>I'm trying to add a JLable 'jLable2 to another JLabel 'jLabel1'. 

Why?

>..But
>jLabel2 is not getting displayed.

Try this variant that adds both JLabels directly to the JFrame.
If that is not the effect you are after, there are many alternatives,
including adding them both to a JPanel that is itself added to 
one particular area of the BorderLayout of the JFrame.

<sscce>
import java.awt.BorderLayout;
import javax.swing.*;

public class LabelTest extends JFrame {

  public LabelTest(){

    setDefaultCloseOperation(
      WindowConstants.EXIT_ON_CLOSE);
    JLabel jLabel1 = new JLabel();
    jLabel1.setText("jLabel1");
    JLabel jLabel2 = new JLabel();
    jLabel2.setText(" TEXT ");
    //jLabel1.add(jLabel2);
    getContentPane().add(
      jLabel1, BorderLayout.CENTER);
    getContentPane().add(
      jLabel2, BorderLayout.EAST);
    pack();
  }

  public static void main(String args[]) {
    LabelTest lTest = new LabelTest ();
    lTest.setSize(400,300);
    lTest.setVisible(true);
  }
}
</sscce>

-- 
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200710/1

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web