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


Groups > comp.lang.java.gui > #2693

Re: JLebel as a container

From "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Subject Re: JLebel as a container
Message-ID <7a42e8aa4e8ca@uwe> (permalink)
Newsgroups comp.lang.java.gui
References <1193388915.336894.268240@d55g2000hsg.googlegroups.com>
Date 2011-04-27 15:40 +0000
Organization TDS.net

Show all headers | View raw


  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

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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

csiph-web