Java Basic Problems

JPanel Layout: How to add CheckBox Vertically or Horizontally in JPanel using BoxLayout

We can use BoxLayout in Java to add or show CheckBox Vertically or Horizontally in JPanel.

According to our need in software we have to code in such a way that  CheckBox should appear in JPanel  in Horizontal or Vertical  position.

For  Vertical Position of CheckBox in JPanel : javax.swing.BoxLayout.Y_AXIS       is used

For  Horizontal Position of CheckBox in JPanel : javax.swing.BoxLayout.X_AXIS   is used


Sample  Java code example:


        private javax.swing.JScrollPane jsp_jobWorkProcess = null;

        JCheckBox chk_Embrodary=new JCheckBox(“Embrodary”);

        JCheckBox chk_Cutting=new JCheckBox(“Cutting”);

        JCheckBox cb_Sewing=new JCheckBox(“Sewing”);

        JButton jb_next= new JButton();

        private javax.swing.JScrollPane getSst_jobWorkProcess()


 if(jsp_jobWorkProcess == null) {

 jsp_jobWorkProcess = new javax.swing.JScrollPane();      

JPanel panel=new JPanel();

panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));

JLabel lblHeader=new JLabel(“Job Work Process Selection”);






                                    jsp_jobWorkProcess.setBounds(37, 248, 179, 120);



                        return jsp_jobWorkProcess;