Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #17297 > unrolled thread
| Started by | clusardi2k@aol.com |
|---|---|
| First post | 2012-08-07 12:15 -0700 |
| Last post | 2012-08-09 05:38 -0700 |
| Articles | 20 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | clusardi2k@aol.com |
|---|---|
| Date | 2012-08-07 12:15 -0700 |
| Subject | jLabel setVisible(true) Doesn't Work |
| Message-ID | <ddf6ecbb-1c20-4163-8504-bb2d8a33e41a@googlegroups.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,
[toc] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-08-07 12:33 -0700 |
| Message-ID | <jvrqid$k8k$1@dont-email.me> |
| In reply to | #17297 |
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>
[toc] | [prev] | [next] | [standalone]
| From | clusardi2k@aol.com |
|---|---|
| Date | 2012-08-07 15:22 -0700 |
| Message-ID | <75d52d16-d119-4cee-a9b3-426de8ccbb5d@googlegroups.com> |
| In reply to | #17298 |
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,
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-08-07 19:08 -0400 |
| Message-ID | <jvs6uv$1df$1@dont-email.me> |
| In reply to | #17308 |
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();
}
});
}
}
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-08-07 22:27 -0400 |
| Subject | Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) |
| Message-ID | <jvsijp$u5l$1@dont-email.me> |
| In reply to | #17309 |
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();
}
});
}
}
[toc] | [prev] | [next] | [standalone]
| From | clusardi2k@aol.com |
|---|---|
| Date | 2012-08-08 05:54 -0700 |
| Subject | Re: Layout Doesn't Work (was: jLabel setVisible(true) Doesn't Work) |
| Message-ID | <e26bb607-9645-4ae7-9a43-4603d4bfcfce@googlegroups.com> |
| In reply to | #17312 |
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();
}
});
}
}
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-08-08 11:22 -0400 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <jvtvve$4tl$1@dont-email.me> |
| In reply to | #17349 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-08-08 14:00 -0400 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <jvu99j$v0b$1@dont-email.me> |
| In reply to | #17352 |
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.
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-08-08 08:20 -0700 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <jvu03u$4ok$1@dont-email.me> |
| In reply to | #17349 |
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>
[toc] | [prev] | [next] | [standalone]
| From | clusardi2k@aol.com |
|---|---|
| Date | 2012-08-08 09:24 -0700 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <bddfefd2-26be-4ebe-ba11-7bec2710fc19@googlegroups.com> |
| In reply to | #17353 |
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;
}
[toc] | [prev] | [next] | [standalone]
| From | clusardi2k@aol.com |
|---|---|
| Date | 2012-08-08 10:22 -0700 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <7a7e6564-2761-4592-ad45-b071e0b25f0e@googlegroups.com> |
| In reply to | #17354 |
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.LEADING)
.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.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(270, 270, 270)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.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
}
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-08-08 10:31 -0700 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <jvu7pd$lt5$1@dont-email.me> |
| In reply to | #17356 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-08-08 13:49 -0400 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <jvu8lt$qbb$1@dont-email.me> |
| In reply to | #17356 |
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.
[toc] | [prev] | [next] | [standalone]
| From | clusardi2k@aol.com |
|---|---|
| Date | 2012-08-08 11:15 -0700 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <8132d479-6580-4c7a-945b-550058db3119@googlegroups.com> |
| In reply to | #17356 |
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.LEADING)
.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.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(270, 270, 270)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.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
}
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-08-08 11:48 -0700 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <jvuc9j$ie9$1@dont-email.me> |
| In reply to | #17363 |
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?
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-08-10 10:09 -0400 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <k034gl$b95$1@dont-email.me> |
| In reply to | #17363 |
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); }});
}
}
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-08-10 10:20 -0400 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <k0354u$far$1@dont-email.me> |
| In reply to | #17572 |
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);
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2012-08-10 13:48 -0400 |
| Subject | Re: Layout Doesn't Work |
| Message-ID | <k03hag$rom$1@dont-email.me> |
| In reply to | #17572 |
> pack(); > label.setPreferredSize(label.getPreferredSize()); > label.setVisible(false); - setVisible(true);
[toc] | [prev] | [next] | [standalone]
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Date | 2012-08-07 22:09 -0400 |
| Message-ID | <nospam-9043A1.22090607082012@news.aioe.org> |
| In reply to | #17297 |
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>
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-08-09 05:38 -0700 |
| Message-ID | <mpb7281jj5sh4lqqgtslhh9usgcni2e434@4ax.com> |
| In reply to | #17297 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web