SWING / NOTES</>↗Swing31 Jan 2009
This example shows how we can create border for swing components. In the example below we set border of a JPanel component. Some border implementation that we use below including LineBorder, BevelBorder, EtchedBorder and MatteBorder. package org.kodejava.swing; import javax.swing.*; import javax.swing.border.LineBorder; import javax.swing.border.BevelBorder; import javax.swing.border.EtchedBorder; import javax.swing.border.MatteBorder; import java.awt.*; public class BorderDe...
SWING / NOTES</>↗Swing27 Jan 2009
This example shows you how to create a ButtonGroup for grouping our radio buttons components into a single group. In this example you can also see that we add an action listener to the radio buttons. package org.kodejava.swing; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class ButtonGroupDemo extends JFrame { public ButtonGroupDemo() { […]
SWING / NOTES</>↗Swing23 Jan 2009
Below we create a JRadioButton and pass an action handle to the component so that we know when the component is clicked. package org.kodejava.swing; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; public class RadioButtonCreateAction extends JFrame { public RadioButtonCreateAction() { initializeUI(); } public static void main(String[] args) { SwingUtilities.invokeLater( () -> new RadioButtonCreateAction().setVisible(true)); } private void […]
SWING / NOTES</>↗Swing19 Jan 2009
This simple example shows you how to create a JRadioButton component. To create an instance of JRadioButton we can simply call its constructor and pass a string as the radio button text. We can also call the constructor with a boolean value after the text to indicate whether the radio button is selected or not. […]
SWING / NOTES</>↗Swing18 Jan 2009
In this example you can see how we do an absolute positioning to a swing component in the content panel. In this example we use a JPanel as the container, and we didn’t set a layout manager into it. To position the component on the container we use the setBounds() method of the component. This […]
SWING / NOTES</>↗Swing17 Jan 2009
This example use the GridLayout to create a four by four grid layout. One each of the grid we place a JTextField component to read user inputs. package org.kodejava.swing; import javax.swing.*; import java.awt.*; public class GridLayoutDemo extends JFrame { public GridLayoutDemo() { initializeUI(); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new GridLayoutDemo().setVisible(true)); } […]