aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes yet another jLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "yet another jLabel" Watch "yet another jLabel" New topic
Author

yet another jLabel

Martin Smiesko
Greenhorn

Joined: Jul 07, 2009
Posts: 2
Hello,

I am new and desperate

I use netbeans to make some easy java programming. Most of the time I learn from the examples on the net, so I am not much more than a complete beginner. My problem:

Is there an easy way how to update JLabel using setText()? I have designed in Netbeans a main frame and then a dialog (jDialog_Submitted), that has a label (jLabel_Submitted, set to "some string" value as a default). I would like this label to change appropriately before the dialog appears. I use setText("my string"), however after calling this sequence I don't see any label at all.

jLabel_Submitted.setText("File was submitted.");
jDialog_Submitted.pack();
jDialog_Submitted.setLocationRelativeTo(null);
jDialog_Submitted.setVisible(true);

I read > 50 websites/forums in order to understand how to do this simple (?!) thing, but cannot find anything I would understand...

Please, help me.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2091
    
    7
I don't see any label at all


Well based on the 4 lines of code provided, you don't even add the label to the dialog.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.

Create the program manually and don't use the NetBeans GUI generator so you understand what it happening.
Martin Smiesko
Greenhorn

Joined: Jul 07, 2009
Posts: 2
I first design the things visually (drag & drop from the palette of Swing containers) in NetBeans environment.
The hierarchy is as follows:



Then I just use the components as I need and add small portions of the code in editor. I thought that jLabel is always associated with jDialog and that just setting new text using jLabel_Submitted.setText("whatever") will work, but I guess one has to do some kind of "refresh" after this change...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

You wouldn't need to refresh the GUI after you change the label, but you should most definitely add the label to the dialog.

But perhaps you may want to check out JOptionPane. It is used quite often for quick dialogs, especially for question asking and message showing.

For instance:

You could try out all of the static methods for showing dialog to see what they all do.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: yet another jLabel
 
Similar Threads
URL's within a container
JDialog is blank whilst other tasks are running
Updating a JLabel on a JPanel
NullPointerException Applet Observer
actionListener for JLabel