Lecture 18 - GUI 2 - Component and Layout Managers Swing...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Component and Layout Managers Swing Components Are GUI elements that can be manipulated or seen o Also called controls or widgets Most Swing components inherit (indirectly) from the abstract class JComponent o Has methods and fields for Size (preferred, minimum, maximum) Thickness of surrounding lines and insets Etc. Get used to using documentation Adding Components to Containers Containers are displayable objects that can hold components o Eg: JFrame, JApplet A component must be added to a container to be visible o Use the add() method Too add to a JFrame, you add to its content pane o Eg: JFrame frame = new JFrame(“Demo”); JButton button = new JButton(“Enter”); frame.getContentPane().add(button); Key Swing Component JLabel o Is a string and/or image used to label other parts of the interface o Example Code ImageIcon icon = new ImageIcon(“star.gif”); JLabel label = new JLabel(“This is a label`, icon, JLabel.CENTER); frame.getContentPane().add(label); JButton
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Lecture 18 - GUI 2 - Component and Layout Managers Swing...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online