This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "yet another jLabel" Watch "yet another jLabel" New topic

yet another jLabel

Martin Smiesko

Joined: Jul 07, 2009
Posts: 2

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.");

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: 2419
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

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

Joined: Oct 27, 2005
Posts: 20202

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: yet another jLabel
It's not a secret anymore!