• 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

Refreshing graphics in Netbeans GUI builder

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I am new to the GUI builder, and was wondering how to set up a panel to refresh graphics automatically say, every 200 ms or so. I have noticed the "double buffered" check box in the properties window for labels and other components, but it doesn't seem to do anything. For instance, if I have a JLabel linked to a boolean variable, and the variable changes from true to false, I want the JLabel to refresh to false automatically. Is this easily accomplishable?

Thanks very much,

Jon
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You likely want to use a Swing Timer here, and in the timer's ActionListener's actionPerformed method, you can update your program's state. If you update data that is used to do drawing or painting of the JPanel then call repaint on your JPanel. Note that if you change your JLabel's text with setText, it will automatically update itself in your GUI.

Having said this, I have to strongly recommend that if you are serious about learning and using Swing, you put the NetBeans code generation to the side for a bit and learn to do it by hand. I am somewhat opinionated on this, but my experience here and in other fora are that use of NetBeans to generate code sets back Swing education by months at the least.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mr Fish, please check your private messages for an important administrative matter. Thank you.
 
Jon Fanten
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fixed my name, thanks for letting me know.

Jon
 
Jon Fanten
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pete,

Thanks for the quick reply. Actually at first I did attempt to create my own layout, and succeeded using an absolute layout-- but obviously this is horrible practice and the end result did not work on certain resolutions or resize successfully (I am not a Java programmer normally if you couldn't tell:). For the next version I tried using GridLayout, but I just couldn't get the gridx, gridy, gridwidth, etc to work as I expected them to. So that's when I resorted to the Netbeans GUI builder. If you think it is worth another go, I will try again. Perhaps you could suggest the right layout? Here is a screenshot of the GUI. (I have removed some of the text to keep company and industry details anonymous.) Do you think GridLayout is the best idea? All I really want to do is make it more resizable, and have a more standard like Windows appearance in general.
screenshot.JPG
[Thumbnail for screenshot.JPG]
screenshot
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would use several nested JPanels each using their own layout. For instance, the main JPanel that holds the entire app could use a BorderLayout.

On the NORTH section of the BorderLayout I"d use a JPanel that uses GridLayout(1, 3) <== for 1 row, 3 cols
In the Middle section of this, I'd use a JLabel("GENERATOR PANEL", SwingConstants.CENTER) that has text placed center via SwingConstants.CENTER. On the right of the NORTH JPanel I'd display the date and time using a JLabel set up with SwingConstants.RIGHT.

The SOUTH section of the main panel could hold a status bar JPanel or JLabel.

In the CENTER section I'd use a JPanel (say called middlePanel) that uses a BoxLayout(middlePanel, BoxLayout.PAGE_AXIS); so that components could be laid out one on top of the other.
I'd add several JPanels inside of this, the first holding the "Write statistics... JCheckBox, and other components up to and including the Last Log Recorded JLabel could be created using GridBagLayout.
The JPanel below this with the voltage and current info could be made with GridLayout, except that bottom line may need a different layout altogether such as FlowLayout.
The JPanel below this showing various ?warning lights? would be a JPanel using GridLayout((0, 3) which stands for 3 columns and any number of rows.

I'd probably modularize all of this by creating different components in separate classes and give them public methods to allow interaction with a master class, and would try to write the classes with an eye towards an MVC pattern so as to separate logic from GUI.

Then if I didn't like this set up, I could change individual components easily enough.

YMMV.

Best of luck
 
reply
    Bookmark Topic Watch Topic
  • New Topic