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


Groups > comp.lang.java.programmer > #17572

Re: Layout Doesn't Work

From Jeff Higgins <jeff@invalid.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Layout Doesn't Work
Date 2012-08-10 10:09 -0400
Organization A noiseless patient Spider
Message-ID <k034gl$b95$1@dont-email.me> (permalink)
References (5 earlier) <e26bb607-9645-4ae7-9a43-4603d4bfcfce@googlegroups.com> <jvu03u$4ok$1@dont-email.me> <bddfefd2-26be-4ebe-ba11-7bec2710fc19@googlegroups.com> <7a7e6564-2761-4592-ad45-b071e0b25f0e@googlegroups.com> <8132d479-6580-4c7a-945b-550058db3119@googlegroups.com>

Show all headers | View raw


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

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;
import javax.swing.WindowConstants;

@SuppressWarnings("serial")
public final class Hide_Show_Label_with_Delay
extends JFrame {

   private final JButton button;
   private final JLabel label;
   private final Timer timer;

   private Hide_Show_Label_with_Delay() {

     button = new JButton("Show");
     label = new JLabel("Label");
     timer = new Timer(3000, new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {
         button.setEnabled(true); }});

     setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     setResizable(false);

     button.addActionListener(new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {
         if (label.isVisible()) {
           label.setVisible(false);
           button.setText("Show");
           button.setEnabled(false);
           timer.start();
         } else {
           label.setVisible(true);
           button.setText("Hide");
           button.setEnabled(false);
           timer.start();
         } }});

     GroupLayout layout
       = new GroupLayout(getContentPane());
     getContentPane().setLayout(layout);
     layout.setAutoCreateGaps(true);
     layout.setAutoCreateContainerGaps(true);
     layout.setHonorsVisibility(label, Boolean.FALSE);

     layout.setHorizontalGroup(
       layout.createSequentialGroup()
         .addComponent(button)
         .addComponent(label));
     layout.setVerticalGroup(
       layout.createParallelGroup(
         GroupLayout.Alignment.BASELINE)
         .addComponent(button)
         .addComponent(label));

     pack();
     label.setPreferredSize(label.getPreferredSize());
     label.setVisible(false);
     setVisible(true);
   }

   public static void main(String args[]) {
     final Hide_Show_Label_with_Delay gui
       = new Hide_Show_Label_with_Delay();
     java.awt.EventQueue.invokeLater(new Runnable() {
       public void run() {
         gui.setVisible(true); }});
   }
}

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


Thread

jLabel setVisible(true) Doesn't Work clusardi2k@aol.com - 2012-08-07 12:15 -0700
  Re: jLabel setVisible(true) Doesn't Work markspace <-@.> - 2012-08-07 12:33 -0700
    Re: jLabel setVisible(true) Doesn't Work clusardi2k@aol.com - 2012-08-07 15:22 -0700
      Re: jLabel setVisible(true) Doesn't Work Jeff Higgins <jeff@invalid.invalid> - 2012-08-07 19:08 -0400
        Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) Jeff Higgins <jeff@invalid.invalid> - 2012-08-07 22:27 -0400
          Re: Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) clusardi2k@aol.com - 2012-08-08 05:54 -0700
            Re: Layout Doesn't Work Jeff Higgins <jeff@invalid.invalid> - 2012-08-08 11:22 -0400
              Re: Layout Doesn't Work Jeff Higgins <jeff@invalid.invalid> - 2012-08-08 14:00 -0400
            Re: Layout Doesn't Work markspace <-@.> - 2012-08-08 08:20 -0700
              Re: Layout Doesn't Work clusardi2k@aol.com - 2012-08-08 09:24 -0700
                Re: Layout Doesn't Work clusardi2k@aol.com - 2012-08-08 10:22 -0700
                Re: Layout Doesn't Work markspace <-@.> - 2012-08-08 10:31 -0700
                Re: Layout Doesn't Work Jeff Higgins <jeff@invalid.invalid> - 2012-08-08 13:49 -0400
                Re: Layout Doesn't Work clusardi2k@aol.com - 2012-08-08 11:15 -0700
                Re: Layout Doesn't Work markspace <-@.> - 2012-08-08 11:48 -0700
                Re: Layout Doesn't Work Jeff Higgins <jeff@invalid.invalid> - 2012-08-10 10:09 -0400
                Re: Layout Doesn't Work Jeff Higgins <jeff@invalid.invalid> - 2012-08-10 10:20 -0400
                Re: Layout Doesn't Work Jeff Higgins <jeff@invalid.invalid> - 2012-08-10 13:48 -0400
  Re: jLabel setVisible(true) Doesn't Work "John B. Matthews" <nospam@nospam.invalid> - 2012-08-07 22:09 -0400
  Re: jLabel setVisible(true) Doesn't Work Roedy Green <see_website@mindprod.com.invalid> - 2012-08-09 05:38 -0700

csiph-web