Bookmark Topic Watch Topic
friki data migration
Ranch Hand
Posts: 772
  • Mark post as helpful
  • send pies
  • Report post to moderator
SwingIsAProperNoun - Avoiding a common mistake when referring to Swing in writing or speech.




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. 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.



Links to further information

  • Swing Tutorial
  • The full text of the first edition of Swing is available
  • Article Speed up your Swing GUI construction with better building blocks
  • Article Component Titled Border
  • RSyntaxTextArea, an LGPL-ed syntax highlighting text (editing) component
  • Artcile Translucent and Shaped Swing Windows

  • CategoryFaq
      Bookmark Topic Watch Topic
    • New Topic