Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: clusardi2k@aol.com Newsgroups: comp.lang.java.programmer Subject: Re: Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) Date: Wed, 8 Aug 2012 05:54:41 -0700 (PDT) Organization: http://groups.google.com Lines: 87 Message-ID: References: <75d52d16-d119-4cee-a9b3-426de8ccbb5d@googlegroups.com> NNTP-Posting-Host: 198.151.13.60 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1344430816 1641 127.0.0.1 (8 Aug 2012 13:00:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 8 Aug 2012 13:00:16 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=198.151.13.60; posting-account=r24XpwkAAABfAJg5TJRsTScS4AL5MjOT User-Agent: G2/1.0 Xref: csiph.com comp.lang.java.programmer:17349 Nice project thanks, but I have two questions: (Q1) How can you either modify this code or create a different project to u= se controls that were dragged to the JFrame from the swing Palette. The cod= e is not to create the buttons, JFrame, JPanel, or JLabel. I.E.:In Design View suppose you have a JFrame, jPanel1, jButton1, jButton2,= and jLabel1 already on the Frame. They were dragged to the form. Your curr= ent project did not create them. The buttons and label are in the jPanel. H= ow would you make jLabel1 become invisible and invisible using two buttons. (Q2) I noticed that int the below project the buttons move when one of the = buttons is pressed. How can you stop that from happening. On Tuesday, August 7, 2012 10:27:46 PM UTC-4, Jeff Higgins wrote: import java.awt.event.ActionEvent;=20 import java.awt.event.ActionListener;=20 import java.awt.event.KeyEvent;=20 import javax.swing.JButton;=20 import javax.swing.JFrame;=20 import javax.swing.JLabel;=20 import javax.swing.JPanel;=20 @SuppressWarnings("serial")=20 public class Scratch extends JPanel implements ActionListener {=20 private JButton vButton, iButton;=20 private JLabel label;=20 public Scratch() {=20 vButton =3D new JButton("Visible");=20 vButton.setMnemonic(KeyEvent.VK_D);=20 vButton.setToolTipText("Sets Label visible (true)");=20 vButton.setActionCommand("visible");=20 vButton.addActionListener(this);=20 vButton.setEnabled(false);=20 iButton =3D new JButton("Invisible");=20 iButton.setMnemonic(KeyEvent.VK_E);=20 iButton.setToolTipText("Sets Label visible (false)");=20 iButton.setActionCommand("invisible");=20 iButton.addActionListener(this);=20 label =3D new JLabel("Scratch");=20 add(vButton);=20 add(label);=20 add(iButton);=20 }=20 public void actionPerformed(ActionEvent e) {=20 if ("invisible".equals(e.getActionCommand())) {=20 label.setVisible(false);=20 vButton.setEnabled(true);=20 iButton.setEnabled(false);=20 } else {=20 label.setVisible(true);=20 vButton.setEnabled(false);=20 iButton.setEnabled(true);=20 }=20 }=20 private static void createAndShowGUI() {=20 JFrame frame =3D new JFrame("Scratch");=20 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);=20 Scratch scratch =3D new Scratch();=20 frame.setContentPane(scratch);=20 frame.pack();=20 frame.setVisible(true);=20 }=20 public static void main(String[] args) {=20 javax.swing.SwingUtilities.invokeLater(new Runnable() {=20 public void run() {=20 createAndShowGUI();=20 }=20 });=20 }=20 }=20