Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #17367 > unrolled thread
| Started by | "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> |
|---|---|
| First post | 2012-08-08 19:04 +0000 |
| Last post | 2012-08-09 18:44 +0000 |
| Articles | 20 — 10 participants |
Back to article view | Back to comp.lang.java.programmer
jLabel setVisible(true) Doesn't Work "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: jLabel setVisible(true) Doesn't Work "markspace" <markspace@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: jLabel setVisible(true) Doesn't Work "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: jLabel setVisible(true) Doesn't Work "Jeff Higgins" <jeff.higgins@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) "Jeff Higgins" <jeff.higgins@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: Layout Doesn't Work "markspace" <markspace@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: Layout Doesn't Work "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: Layout Doesn't Work "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: Layout Doesn't Work "markspace" <markspace@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: Layout Doesn't Work "Jeff Higgins" <jeff.higgins@1:261/38.remove-r72-this> - 2012-08-08 20:06 +0000
Re: Layout Doesn't Work "clusardi2k" <clusardi2k@1:261/38.remove-r72-this> - 2012-08-08 20:06 +0000
Re: Layout Doesn't Work "markspace" <markspace@1:261/38.remove-k2r-this> - 2012-08-09 18:44 +0000
Re: Layout Doesn't Work "Jeff Higgins" <jeff.higgins@1:261/38.remove-t9h-this> - 2012-08-10 18:39 +0000
Re: Layout Doesn't Work "Jeff Higgins" <jeff.higgins@1:261/38.remove-t9h-this> - 2012-08-10 18:39 +0000
Re: Layout Doesn't Work "Jeff Higgins" <jeff.higgins@1:261/38.remove-6gh-this> - 2012-08-10 19:41 +0000
Re: Layout Doesn't Work "Jeff Higgins" <jeff.higgins@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: Layout Doesn't Work "Jeff Higgins" <jeff.higgins@1:261/38.remove-r72-this> - 2012-08-08 20:06 +0000
Re: jLabel setVisible(true) Doesn't Work "John B. Matthews" <john.b..matthews@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: jLabel setVisible(true) Doesn't Work "Roedy Green" <roedy.green@1:261/38.remove-k2r-this> - 2012-08-09 18:44 +0000
| From | "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Subject | jLabel setVisible(true) Doesn't Work |
| Message-ID | <5022AB7A.56317.calajapr@time.synchro.net> |
From: clusardi2k@aol.com
I apologize for the simple question, but how do the label setVisible properly.
(1) I dragged a jLabel to my form. I then set it like so:
my_jLabel.setVisible (false);
Later in the project, I set its visibility to true:
my_jLabel.setVisible (true);
But, the label is no where to be found. That's my problem.
(2)FYI: If I do the following after setting it to true, I do see the label:
JOptionPane.showMessageDialog(null,"Is the jLable visible");
(3) Instead of using the show method, doing the following after setting the
label visibility to true did not help.
my_jLabel.repaint();
my_jLabel.validate();
(4) Replacing the showMessageDialog with a sleep did not help.
(5) Replacing the above setVisible in (1) with the following code did not help:
SwingUtilities.invokeLater(new Runnable() { //The EDT (Event Dispatch Thread)
public void run()
{
JLabel myLabel = new JLabel("Old Text");
my_jLabel.setVisible (true);
}
});
(6) Using google to search for an answer isn't helping.
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
[toc] | [next] | [standalone]
| From | "markspace" <markspace@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Message-ID | <5022AB7A.56318.calajapr@time.synchro.net> |
| In reply to | #17367 |
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
[toc] | [prev] | [next] | [standalone]
| From | "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Message-ID | <5022AB7D.56328.calajapr@time.synchro.net> |
| In reply to | #17368 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Jeff Higgins" <jeff.higgins@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Message-ID | <5022AB7D.56329.calajapr@time.synchro.net> |
| In reply to | #17378 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Jeff Higgins" <jeff.higgins@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Subject | Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) |
| Message-ID | <5022AB7E.56332.calajapr@time.synchro.net> |
| In reply to | #17379 |
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
[toc] | [prev] | [next] | [standalone]
| From | "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Subject | Re: Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) |
| Message-ID | <5022AB84.56369.calajapr@time.synchro.net> |
| In reply to | #17382 |
To: Jeff Higgins
From: clusardi2k@aol.com
Nice project thanks, but I have two questions:
(Q1) How can you either modify this code or create a different project to use
controls that were dragged to the JFrame from the swing Palette. The code 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 current
project did not create them. The buttons and label are in the jPanel. How 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;
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
[toc] | [prev] | [next] | [standalone]
| From | "markspace" <markspace@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5022AB85.56373.calajapr@time.synchro.net> |
| In reply to | #17419 |
To: clusardi2k From: markspace <-@.> On 8/8/2012 5:54 AM, clusardi2k@aol.com wrote: > Nice project thanks, but I have two questions: > > (Q1) How can you either modify this code or create a different > project to use controls that were dragged to the JFrame from the > swing Palette. The code 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 current project did not create them. The buttons and label > are in the jPanel. How would you make jLabel1 become invisible and > invisible using two buttons. What have you actually tried? Where's your code? What in this tutorial doesn't work for you? <http://netbeans.org/kb/docs/java/gui-functionality.html#Exercise_3> --- 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]
| From | "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5022AB85.56374.calajapr@time.synchro.net> |
| In reply to | #17422 |
To: markspace
From: clusardi2k@aol.com
On Wednesday, August 8, 2012 11:20:27 AM UTC-4, markspace wrote:
>
> What have you actually tried? Where's your code?
> What in this tutorial doesn't work for you?
> <http://netbeans.org/kb/docs/java/gui-functionality.html#Exercise_3>
Thanks, it appears small projects work well! So, I have to investigate why
setVisible is not working for me.
Basically, I'm going to move the below code down through my project to see
where things stop working. I'll report back in a few minutes!
if ( jLabel1.isVisible() )
{
jLabel1.setVisible(false);
return;
}
else if ( 1 == 1 )
{
jLabel1.setVisible(true);
return;
}
--- 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]
| From | "clusardi2k" <clusardi2k@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5022AB86.56376.calajapr@time.synchro.net> |
| In reply to | #17423 |
To: clusardi2k
From: clusardi2k@aol.com
On Wednesday, August 8, 2012 12:24:39 PM UTC-4, (unknown) wrote:
> I'll report back in a few minutes!
It gave me confusing results. It was like the project ran too fast to ever
display the label. I thought this was nonsense, so I created the below project.
The big question now becomes how do I (using the below project) get jLabel1 to
be visible while the project is executing in the for loops?
Information about 3 of my button clicks:
Start run jLabel1 is visible :-)
(1st button press)
jLabel1 disappears at end of method and never comes back up!
(2nd button press)
jLabel1 never is seen
(3rd button press)
jLabel1 never is seen
//Code:
package hide_show_label_with_icon;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Hide_Show_Label_with_Icon extends javax.swing.JFrame {
public Hide_Show_Label_with_Icon() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("jLabel1");
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGap(46, 46, 46)
.addComponent(jButton1)
.addGap(60, 60, 60)
.addComponent(jLabel1)
.addContainerGap(233, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGap(270, 270, 270)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al
ignment.BASELINE)
.addComponent(jButton1)
.addComponent(jLabel1))
.addContainerGap(36, Short.MAX_VALUE))
);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("jLabel1.isVisible is " + jLabel1.isVisible());
jLabel1.setVisible(true);
for (int i = 0;i < 100000; i++)
for (int i2 = 0;i2 < 100000; i2++);
for (int i3 = 0;i3 < 100000; i3++);
System.out.println("jLabel1.isVisible is " + jLabel1.isVisible());
jLabel1.setVisible(false);
System.out.println("Done");
System.out.println();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Hide_Show_Label_with_Icon().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
--- 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]
| From | "markspace" <markspace@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5022AB86.56378.calajapr@time.synchro.net> |
| In reply to | #17426 |
To: clusardi2k From: markspace <-@.> On 8/8/2012 10:22 AM, clusardi2k@aol.com wrote: > for (int i = 0;i < 100000; i++) > for (int i2 = 0;i2 < 100000; i2++); > for (int i3 = 0;i3 < 100000; i3++); You can't block the EDT like this. The loops stop the EDT from displaying any updates to the GUI. Use a SwingWorker to execute tasks off the EDT. <http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html> Reading that entire trail (Concurrency in Swing) will be a benefit to you. --- 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]
| From | "Jeff Higgins" <jeff.higgins@1:261/38.remove-r72-this> |
|---|---|
| Date | 2012-08-08 20:06 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5022BA8F.56384.calajapr@time.synchro.net> |
| In reply to | #17426 |
To: clusardi2k From: Jeff Higgins <jeff@invalid.invalid> On 08/08/2012 01:22 PM, clusardi2k@aol.com wrote: > On Wednesday, August 8, 2012 12:24:39 PM UTC-4, (unknown) wrote: >> I'll report back in a few minutes! > > It gave me confusing results Are you a troll? If so, nice! If not, yep. --- 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]
| From | "clusardi2k" <clusardi2k@1:261/38.remove-r72-this> |
|---|---|
| Date | 2012-08-08 20:06 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5022BA90.56387.calajapr@time.synchro.net> |
| In reply to | #17426 |
To: clusardi2k
From: clusardi2k@aol.com
So, how do you convert the below project to use SwingWorker?
Also, in general, how do you stop buttons and things from moving around when
things go invisible and vice versa.
Thanks,
On Wednesday, August 8, 2012 1:22:05 PM UTC-4, (unknown) wrote:
//Code:
package hide_show_label_with_icon;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Hide_Show_Label_with_Icon extends javax.swing.JFrame {
public Hide_Show_Label_with_Icon() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setText("jLabel1");
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGap(46, 46, 46)
.addComponent(jButton1)
.addGap(60, 60, 60)
.addComponent(jLabel1)
.addContainerGap(233, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(layout.createSequentialGroup()
.addGap(270, 270, 270)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al
ignment.BASELINE)
.addComponent(jButton1)
.addComponent(jLabel1))
.addContainerGap(36, Short.MAX_VALUE))
);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("jLabel1.isVisible is " + jLabel1.isVisible());
jLabel1.setVisible(true);
for (int i = 0;i < 100000; i++)
for (int i2 = 0;i2 < 100000; i2++);
for (int i3 = 0;i3 < 100000; i3++);
System.out.println("jLabel1.isVisible is " + jLabel1.isVisible());
jLabel1.setVisible(false);
System.out.println("Done");
System.out.println();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Hide_Show_Label_with_Icon().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
--- 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]
| From | "markspace" <markspace@1:261/38.remove-k2r-this> |
|---|---|
| Date | 2012-08-09 18:44 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5023FE2F.56414.calajapr@time.synchro.net> |
| In reply to | #17435 |
To: clusardi2k From: markspace <-@.> On 8/8/2012 11:15 AM, clusardi2k@aol.com wrote: > So, how do you convert the below project to use SwingWorker? Did you read the tutorial at the link I send you? Where's the code you wrote after reading that? --- 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]
| From | "Jeff Higgins" <jeff.higgins@1:261/38.remove-t9h-this> |
|---|---|
| Date | 2012-08-10 18:39 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <50254C52.56585.calajapr@time.synchro.net> |
| In reply to | #17435 |
To: clusardi2k
From: Jeff Higgins <jeff@invalid.invalid>
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); }});
}
}
--- 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]
| From | "Jeff Higgins" <jeff.higgins@1:261/38.remove-t9h-this> |
|---|---|
| Date | 2012-08-10 18:39 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <50254C52.56586.calajapr@time.synchro.net> |
| In reply to | #17638 |
To: Jeff Higgins
From: Jeff Higgins <jeff@invalid.invalid>
On 08/10/2012 10:09 AM, Jeff Higgins wrote:
> timer = new Timer(3000, new ActionListener() {
> @Override
> public void actionPerformed(ActionEvent e) {
> button.setEnabled(true); }});
+ timer.setRepeats(false);
--- 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]
| From | "Jeff Higgins" <jeff.higgins@1:261/38.remove-6gh-this> |
|---|---|
| Date | 2012-08-10 19:41 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <50255B5A.56602.calajapr@time.synchro.net> |
| In reply to | #17638 |
To: Jeff Higgins From: Jeff Higgins <jeff@invalid.invalid> > pack(); > label.setPreferredSize(label.getPreferredSize()); > label.setVisible(false); - setVisible(true); --- 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]
| From | "Jeff Higgins" <jeff.higgins@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5022AB85.56372.calajapr@time.synchro.net> |
| In reply to | #17419 |
To: clusardi2k From: Jeff Higgins <jeff@invalid.invalid> On 08/08/2012 08:54 AM, clusardi2k@aol.com wrote: > Nice project thanks, but I have two questions: > > (Q1) How can you either modify this code or create a different project to use controls that were dragged to the JFrame from the swing Palette. The code is not to create the buttons, JFrame, JPanel, or JLabel. > I'm not certain what a swing Palette is. Probably a graphical GUI builder of some sort. Two that I am aware of are associated with the Netbeans and Eclipse IDEs. Questions regarding these tools are probably better asked in their respective forums. For Netbeans somewhere near here: <http://forums.netbeans.org/> For Eclipse near here: <http://www.eclipse.org/forums/index.php?t=thread&frm_id=214> > 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 current project did not create them. The buttons and label are in the jPanel. How 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. > You will need to let your LayoutManager know your intentions. The best I can offer is a pointer to the Swing tutorial on LayoutManagers. <> How your builder practices layout is better learned from it's documentation and body of practitioners. Since my last post I have come up with a possible use for a disappearing label. In the TextComponentDemo, located here: <http://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html> you might use the technique to enable/disable the status label component. I'm not sure it's a great idea but, what the heck. I just about have the code stripped down to demonstrate the idea and will post back here when I am able. Unless of course someone in the meantime writes in telling me that that is a real crappy idea, and comes up with something better. --- 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]
| From | "Jeff Higgins" <jeff.higgins@1:261/38.remove-r72-this> |
|---|---|
| Date | 2012-08-08 20:06 +0000 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <5022BA8F.56385.calajapr@time.synchro.net> |
| In reply to | #17424 |
To: Jeff Higgins From: Jeff Higgins <jeff@invalid.invalid> On 08/08/2012 11:22 AM, Jeff Higgins wrote: > Since my last post I have come up with a possible use for > a disappearing label. > In the TextComponentDemo, located here: > <http://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html> > > you might use the technique to enable/disable the status label > component. I'm not sure it's a great idea but, what the heck. I just > about have the code stripped down to demonstrate the idea and will post > back here when I am able. Unless of course someone in the meantime > writes in telling me that that is a real crappy idea, and comes up with > something better. > Nope, turns out Container's add and remove methods work better here. --- 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]
| From | "John B. Matthews" <john.b..matthews@1:261/38.remove-qhs-this> |
|---|---|
| Date | 2012-08-08 19:04 +0000 |
| Message-ID | <5022AB7E.56331.calajapr@time.synchro.net> |
| In reply to | #17367 |
To: clusardi2k From: "John B. Matthews" <nospam@nospam.invalid> In article <ddf6ecbb-1c20-4163-8504-bb2d8a33e41a@googlegroups.com>, clusardi2k@aol.com wrote: > (3) Instead of using the show method, doing the following after > setting the label visibility to true did not help. > > my_jLabel.repaint(); > my_jLabel.validate(); Using validate() is appropriate if you add or remove components or change the Container's layout, as shown here [1]. When required, repaint() should be invoked _after_ validate(). CardLayout, shown here [2], is often a better alternative. [1] <http://stackoverflow.com/a/5751044/230513> [2] <http://stackoverflow.com/a/5655843/230513> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews> --- 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]
| From | "Roedy Green" <roedy.green@1:261/38.remove-k2r-this> |
|---|---|
| Date | 2012-08-09 18:44 +0000 |
| Message-ID | <5023FE3F.56502.calajapr@time.synchro.net> |
| In reply to | #17367 |
To: clusardi2k From: Roedy Green <see_website@mindprod.com.invalid> On Tue, 7 Aug 2012 12:15:11 -0700 (PDT), clusardi2k@aol.com wrote, quoted or indirectly quoted someone who said : >But, the label is no where to be found. That's my problem. The background colour setBackground() is ignored unless you do a setOpaque( true ). See http://mindprod.com/jgloss/jlabel.html for sample code. -- Roedy Green Canadian Mind Products http://mindprod.com A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. ~ Max Planck 1858-04-23 1947-10-04 --- 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