JavaRanch Home    
 
This page:         last edited 19 October 2013         What's Changed?         Edit

Swing Faq   

SwingIsAProperNoun - Avoiding a common mistake when referring to Swing in writing or speech.

PreventingEnterFromChangingTheRowInJTable

BackgroundImageOnJPanel

JProgressBarDoesntUpdate

PlotTest - simple example of how to create an X/Y graph; can be changed to use AWT easily

PlotSineCurve - simple example of how to draw a curve; can be changed to use AWT easily

NumericTextField - how to create a text field that only accepts numbers as input

ComponentDoesntUpdatePromptly - Usage of SwingWorker? for background tasks


Q. I created a JOptionPane.showConfirmDialog and no matter which button I have focused, when I hit enter, I always get the OK result.

A. Default button behavior is dependent on the Look and Feel you have specified. To get the desired result in Windows, use the Windows Look and Feel for your application.


Q. Why are Swing components called lightweight, while AWT components are heavyweight?

A. Swing components are considered lightweight because they draw themselves and do not rely on native calls to the OS. AWT (And SWT for that matter) make calls to the OS and say "Hey, I need a button" and the OS throws them back a button. Swing uses the Graphics2D API to draw its widgets.

Note that not all components in the javax.swing package are lightweight. Namely, top level containers like JFrame are still considered heavyweight components because they extend java.awt.Frame.

While mixing AWT and Swing used to be fraught with problem, updates to Java 6 and 7 have made that less troublesome. See this article for more information on that.

(The above was posted in a Saloon discussion. Further information can be found in this thread and on jGuru.)


Q. What is Java SE 6 Update 10 (a.k.a. Update N a.k.a. Consumer JRE) ?

A. Home page, FAQ

Translucent and Shaped Swing Windows


Q. The GridBagLayout class is too complex for my tastes; is anything simpler available?

A. There is indeed. If all you're looking for is a GridLayout with variable row and column sizes, then GridLayout2 may be for you. If you're looking for even more options, check out SGLayout.

JavaDoc:java.awt.GridLayout

JavaDoc:java.awt.GridBagLayout


Links to further information



CategoryFaq

JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton