public int constCheckBox(String labelTxt, String footerTxt, String chkBoxTxt[]) {
chkBoxes = new JCheckBox[chkBoxTxt.length];
//Ask which data we should show
//This is the panel that everything goes into
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
//This is the panel that contains the banner
JPanel bannerPanel = new JPanel();
bannerPanel.setLayout(new BorderLayout());
//This is the panel that contains the checkboxes. We're using a grid here for an even
//number of checkboxes only. Any other type we may want to use something other than a grid
JPanel chkboxPanel = new JPanel();
chkboxPanel.setLayout(new GridLayout(2,3));
//This is the panel that contains the footer
JPanel footerPanel = new JPanel();
footerPanel.setLayout(new BorderLayout());
//Build the dialog box...
//Include instructions in a label and format that label
JLabel askLabel = new JLabel(labelTxt, SwingConstants.CENTER);
askLabel.setForeground(Color.black);
askLabel.setOpaque(true);
bannerPanel.add(askLabel,BorderLayout.NORTH);
//Start defining checkboxes
for (int i = 0;i < chkBoxTxt.length; i++) {
chkBoxes[i] = new JCheckBox (chkBoxTxt[i],false);
chkboxPanel.add(chkBoxes[i]);
}
//Include the footer text in a label and format that label
JLabel askFooter = new JLabel(footerTxt, SwingConstants.CENTER);
askFooter.setForeground(Color.black);
askFooter.setOpaque(true);
footerPanel.add(askFooter);
//add the bannerPanel and chkboxPanels to the main panel
panel.add(bannerPanel,BorderLayout.NORTH);
panel.add(chkboxPanel,BorderLayout.CENTER);
panel.add(footerPanel,BorderLayout.SOUTH);
//Determine which button was clicked...
int answer = JOptionPane.showConfirmDialog(null, panel,"Choose Data",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
return answer;
}