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”);

                                    panel.add(lblHeader);

                                    panel.add(chk_Embrodary);

                                    panel.add(chk_Cutting);

                                    panel.add(cb_Sewing);

                                    panel.add(getJb_Next());

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

                                    jsp_jobWorkProcess.setViewportView(panel);

                        }

                        return jsp_jobWorkProcess;

            }
.adcode{display:block;}

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

  1. Leonel Heppell says:

    This is a interesting write up. Looking forward to reading more of your work.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: