-
Notifications
You must be signed in to change notification settings - Fork 1
DevFaqNbIdiosyncracies
Common calls that should be done slightly differently in NetBeans than standard Swing apps (loading images, localized strings, showing dialogs)
There are a few cases where NetBeans has convenience classes or facilities that you should use, instead of doing them the way you may be used to. They are:
-
Loading images - Don’t use
ImageIO.read()
orToolkit.loadImage()
- instead, use ImageUtilities.loadImage() - it has an optimized image caching strategy, and will play nicely with NetBeans module class loaders -
Creating icons from images - Rather than use
new ImageIcon(someImage)
, use ImageUtilities.image2Icon(someImage) which manages memory better. -
Loading resource bundles/localized strings - Don’t use
ResourceBundle
directly - instead, use NbBundle.getMessage() - it will play nicely with NetBeans class loaders, andString`s resolved this way can be branded using the standard branding mechanism (this is the way you change the title of your application from "NetBeans" to something else). Also, do not hold a reference to a resource bundle - just call `NbBundle.getMessage()
every time - bundles are cached for a period of time, the call is fast. In a large application, holding resource bundles eats memory wastefully -
Assigning mnemonics to labels and buttons - use Mnemonics to assign text and mnemonic to a widget with one call using one key value pair in properties file and annotate the mnemonic with & character. Also do not reuse the same text if it is used in different UI components. This is more freindly to localization. Tip: Check 'Generate Mnemonics Code' checkbox in properties of your form if you are using NetBeans GUI editing support.
-
Showing dialogs - instead of creating a
JDialog
and showing it, or usingJOptionPane
, use NotifyDescriptor or DialogDescriptor to define your dialog and its contents, then pass these to DialogDisplayer.notify - such dialogs will play nicely with NetBeans' windowing system, global actions, etc. -
Reading/writing/listing files - in most cases, rather than work with
java.io.File
, you will want to work withorg.openide.filesystems.FileObject
. -
Quiting application - you can of course still continue to quit using System.exit() but polite NBP apps should employ LifecycleManager instead. Typical Usage pattern is
LifecycleManager.getDefault().exit()
that is equals toSystem.exit(0)
you don’t provide custom LifecycleManager.
<hr/>
Applies to: NetBeans 6.8 and above
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqNbIdiosyncracies , that was last modified by NetBeans user LiborJelinek on 2011-08-14T15:48:03Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-01-26, and needs to be reviewed.
Apache NetBeans is an effort undergoing incubation at The Apache Software Foundation (ASF).
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.
While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
This wiki is an experiment pending Apache NetBeans Community approval.