JSpinner with ChangeListener

A jspinner generates an event of type ChangeEvent when an item is selected that is sent to listeners of type ChangeListener. Both types are defined in the javax.swing.event package. To obtain the current value of the jspinner, call getValue( ). It returns the current setting. Program       Progarm Source import javax.swing.JFrame; import javax.swing.JSpinner; … Read more…

JList Multiple Selection with getSelectedIndices

The getSelectionIndecies () returns an array of all of the selected indices, in increasing order. Program       Program Source import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.ImageIcon; import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; import java.awt.FlowLayout; import java.awt.Dimension; import java.util.Arrays; class Frame extends JFrame implements ListSelectionListener { private JList list; private JButton image; private … Read more…

JRadioButton(Another Example)

setIcon( ) method possible to change the icon inside a JButton during program execution. Program       Program Source import javax.swing.JFrame; import javax.swing.JRadioButton; import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.FlowLayout; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; class Frame extends JFrame implements ItemListener{ private JButton jb; private JRadioButton jr1,jr2,jr3,jr4; private ImageIcon icon; Frame() { setTitle(“Vehicle Selection”); setLayout(new FlowLayout()); … Read more…

JToggleButton with ItemListener (Another Example)

setIcon( ) method possible to change the icon inside a JButton during program execution. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JToggleButton; import javax.swing.ImageIcon; import java.awt.FlowLayout; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; class Frame extends JFrame implements ItemListener{ private JToggleButton jtb; private JButton jb; Frame() { setTitle(“JToggleButton with ItemListener”); setLayout(new FlowLayout()); setJToggleButton(); setAction(); … Read more…

JButton with setRolloverIcon

setRolloverIcon() you can define different icons that are displayed for the button when it is disabled, pressed, or selected. Another icon can be used as a rollover icon, which is displayed when the mouse is positioned over a button. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.FlowLayout; class Frame extends JFrame … Read more…

JButton with Icon

The swing icons are encapsulated by ImageIcon class. This class paints an image from the image. ImageIcon(String filename) Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.FlowLayout; class Frame extends JFrame { Frame() { setTitle(“JButton with Icon”); setLayout(new FlowLayout()); setButtons(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setButtons() { JButton … Read more…