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


Groups > comp.lang.java.programmer > #17590 > unrolled thread

Re: jLabel setVisible(true) Doesn't Work

Started by"markspace" <markspace@1:261/38.remove-t9h-this>
First post2012-08-10 18:38 +0000
Last post2012-08-10 18:38 +0000
Articles 4 — 3 participants

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: jLabel setVisible(true) Doesn't Work "markspace" <markspace@1:261/38.remove-t9h-this> - 2012-08-10 18:38 +0000
    Re: jLabel setVisible(true) Doesn't Work "clusardi2k" <clusardi2k@1:261/38.remove-t9h-this> - 2012-08-10 18:38 +0000
      Re: jLabel setVisible(true) Doesn't Work "Jeff Higgins" <jeff.higgins@1:261/38.remove-t9h-this> - 2012-08-10 18:38 +0000
        Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) "Jeff Higgins" <jeff.higgins@1:261/38.remove-t9h-this> - 2012-08-10 18:38 +0000

#17590 — Re: jLabel setVisible(true) Doesn't Work

From"markspace" <markspace@1:261/38.remove-t9h-this>
Date2012-08-10 18:38 +0000
SubjectRe: jLabel setVisible(true) Doesn't Work
Message-ID<50254C4A.56537.calajapr@time.synchro.net>
  To: clusardi2k
From: "markspace" <markspace@1:261/38.remove-k2r-this>

  To: clusardi2k
From: "markspace" <markspace@1:261/38.remove-qhs-this>

  To: clusardi2k
From: markspace <-@.>

On 8/7/2012 12:15 PM, clusardi2k@aol.com wrote:

> SwingUtilities.invokeLater(new Runnable()
> { //The EDT (Event Dispatch Thread)
>     public void run()
>     {
>        JLabel myLabel = new JLabel("Old Text");
>        my_jLabel.setVisible (true);


The second to the last line is the problem.  Your label has to be inside 
another component (a container) to be visible.  Changing a local variable will 
never work.  Even changing an instance field won't work unless you've specially 
defined your own component somehow.

Most Swing components are also containers.  However normally you use JFrame and 
JPanel as your containers.  Call the add method, or use the GUI layout tool to 
just drag and drop components onto one.

This might help:

<http://docs.oracle.com/javase/tutorial/uiswing/components/panel.html>

-+- BBBS/Li6 v4.10 Dada-1
 + Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

-+- BBBS/Li6 v4.10 Dada-1
 + Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#17601

From"clusardi2k" <clusardi2k@1:261/38.remove-t9h-this>
Date2012-08-10 18:38 +0000
Message-ID<50254C4C.56547.calajapr@time.synchro.net>
In reply to#17590
  To: markspace
From: "clusardi2k" <clusardi2k@1:261/38.remove-k2r-this>

  To: markspace
From: "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this>

  To: markspace
From: clusardi2k@aol.com

On Tuesday, August 7, 2012 3:33:29 PM UTC-4, markspace wrote:
 Your label has to be inside another component (a container) to be visible.
Changing a local variable will never work. Even changing an instance field 
won't work unless you've specially defined your own component somehow. Most 
Swing components are also containers. However normally you use JFrame and 
JPanel as your containers. Call the add method, or use the GUI layout tool to 
just drag and drop components onto one.

Does anyone have a simple working project of this:

(1) It has a form with a JPanel dragged from the swing control palette, (2) In 
the JPanel a Jlabel is dragged from the swing control palette. (3) The jlabel 
is set to invisible at the start of the project. (4) The project becomes 
visible when a button is pressed. (5) The project becomes invisible when a 
button is pressed.

Thanks,

-+- BBBS/Li6 v4.10 Dada-1
 + Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

-+- BBBS/Li6 v4.10 Dada-1
 + Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#17602

From"Jeff Higgins" <jeff.higgins@1:261/38.remove-t9h-this>
Date2012-08-10 18:38 +0000
Message-ID<50254C4C.56548.calajapr@time.synchro.net>
In reply to#17601
  To: clusardi2k
From: "Jeff Higgins" <jeff.higgins@1:261/38.remove-k2r-this>

  To: clusardi2k
From: "Jeff Higgins" <jeff.higgins@1:261/38.remove-qhs-this>

  To: clusardi2k
From: Jeff Higgins <jeff@invalid.invalid>

On 08/07/2012 06:22 PM, clusardi2k@aol.com wrote:
> On Tuesday, August 7, 2012 3:33:29 PM UTC-4, markspace wrote:
>   Your label has to be inside another component (a container) to be visible.
Changing a local variable will never work. Even changing an instance field 
won't work unless you've specially defined your own component somehow. Most 
Swing components are also containers. However normally you use JFrame and 
JPanel as your containers. Call the add method, or use the GUI layout tool to 
just drag and drop components onto one.
>
> Does anyone have a simple working project of this:
>
> (1) It has a form with a JPanel dragged from the swing control palette,
> (2) In the JPanel a Jlabel is dragged from the swing control palette.
> (3) The jlabel is set to invisible at the start of the project.
> (4) The project becomes visible when a button is pressed.
> (5) The project becomes invisible when a button is pressed.
>
> Thanks,

No. But here's a start. You'll need add the appropriate controls and handlers 
and wrap it in a project.

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Scratch {

   private static void createAndShowGUI() {
     JFrame frame = new JFrame("Scratch");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     JLabel label = new JLabel("Scratch");
     frame.getContentPane().add(label);
     // label.setVisible(false);
     frame.pack();
     frame.setVisible(true);
   }

   public static void main(String[] args) {
     javax.swing.SwingUtilities.invokeLater(new Runnable() {
       public void run() {
         createAndShowGUI();
       }
     });
   }
}

-+- BBBS/Li6 v4.10 Dada-1
 + Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

-+- BBBS/Li6 v4.10 Dada-1
 + Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#17605 — Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work)

From"Jeff Higgins" <jeff.higgins@1:261/38.remove-t9h-this>
Date2012-08-10 18:38 +0000
SubjectLayout Doesn't Work (was: jLabel setVisible(true) Doesn't Work)
Message-ID<50254C4D.56551.calajapr@time.synchro.net>
In reply to#17602
  To: Jeff Higgins
From: "Jeff Higgins" <jeff.higgins@1:261/38.remove-k2r-this>

  To: Jeff Higgins
From: "Jeff Higgins" <jeff.higgins@1:261/38.remove-qhs-this>

  To: Jeff Higgins
From: Jeff Higgins <jeff@invalid.invalid>

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class Scratch extends JPanel implements ActionListener {

   private JButton vButton, iButton;
   private JLabel label;

   public Scratch() {

     vButton = new JButton("Visible");
     vButton.setMnemonic(KeyEvent.VK_D);
     vButton.setToolTipText("Sets Label visible (true)");
     vButton.setActionCommand("visible");
     vButton.addActionListener(this);
     vButton.setEnabled(false);

     iButton = new JButton("Invisible");
     iButton.setMnemonic(KeyEvent.VK_E);
     iButton.setToolTipText("Sets Label visible (false)");
     iButton.setActionCommand("invisible");
     iButton.addActionListener(this);

     label = new JLabel("Scratch");

     add(vButton);
     add(label);
     add(iButton);
   }

   public void actionPerformed(ActionEvent e) {
     if ("invisible".equals(e.getActionCommand())) {
       label.setVisible(false);
       vButton.setEnabled(true);
       iButton.setEnabled(false);
     } else {
       label.setVisible(true);
       vButton.setEnabled(false);
       iButton.setEnabled(true);
     }
   }

   private static void createAndShowGUI() {

     JFrame frame = new JFrame("Scratch");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     Scratch scratch = new Scratch();
     frame.setContentPane(scratch);
     frame.pack();
     frame.setVisible(true);
   }

   public static void main(String[] args) {
     javax.swing.SwingUtilities.invokeLater(new Runnable() {
       public void run() {
         createAndShowGUI();
       }
     });
   }
}

-+- BBBS/Li6 v4.10 Dada-1
 + Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

-+- BBBS/Li6 v4.10 Dada-1
 + Origin: Prism bbs (1:261/38)
-+- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


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


csiph-web