JPanel and BorderFactory

The JPanel class defines something like a physical panel that you can use as a container to group a set of components. However, you can also place a component to which you want to add a border in a JPanel container, and add the border to the JPanel object. You decorate the panel with a … Read more…

JFrame.HIDE_ON_CLOSE

HIDE_ON_CLOSE : The method is used to hide the frame, but the frame doesn’t not terminate. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JOptionPane; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; class Frame extends JFrame implements ActionListener{ private JButton jb1,jb2,jb3; private JFrame sub; Frame() { setTitle(“Main Frame”); setLayout(new FlowLayout()); setButton(); setAction(); setSize(700, 200); … Read more…

JFrame.DO_NOTHING_ON_CLOSE and dispose()

DO_NOTHING_ON_CLOSE   :   makes the close operation for the frame window ineffective. dispose()                                            :   This method is used to close the all frame and finally to terminate the application. Program     … Read more…

JFrame.EXIT_ON_CLOSE and DISPOSE_ON_CLOSE

DISPOSE_ON_CLOSE   :   This method is used to close the current frame. But doesn’t terminate the application. EXIT_ON_CLOSE            :   This method is used to close the all frame and finally to terminate the application Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.FlowLayout; class Frame … Read more…

JFrame pack()

The pack method packs the components within the window based on the component’s preferred sizes. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import java.awt.FlowLayout; class Frame extends JFrame { void makeSizedFrame() { setTitle(“SetSize(700,200)”); setLayout(new FlowLayout()); setButton(); setSize(700, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } void makepackFrame() { setTitle(“Withpack()”); setLayout(new FlowLayout()); setButton(); pack(); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } … Read more…

JComboBox with ItemListener

When the ComboBox item is selected, an item event is generated. This is handled by itemStateChanged() method, the getItem() method gets the JComboBox object that generated the event. Program       Program Source import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JComboBox; import java.awt.FlowLayout; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; class Frame extends JFrame implements ItemListener{ private JComboBox jb; … Read more…