• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

yet another jLabel

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic