use of javax.swing.GroupLayout in project cytoscape-api by cytoscape.
the class LookAndFeelUtil method createOkCancelPanel.
/**
* Use this method to include a help button in the bottom left corner.
* @param helpStr can be a full url, a lookup, or a help page name
*/
public static JPanel createOkCancelPanel(final JButton okBtn, final JButton cancelBtn, String helpStr, JComponent... otherComponents) {
final JPanel panel = new JPanel();
final GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
layout.setAutoCreateContainerGaps(false);
layout.setAutoCreateGaps(true);
final SequentialGroup hg = layout.createSequentialGroup();
final ParallelGroup vg = layout.createParallelGroup(Alignment.CENTER, false);
if (helpStr != null && !helpStr.trim().isEmpty()) {
final JButton helpButton = createHelpButton(helpStr);
hg.addComponent(helpButton);
vg.addComponent(helpButton);
}
if (otherComponents != null) {
for (int i = 0; i < otherComponents.length; i++) {
final JComponent c = otherComponents[i];
hg.addComponent(c);
vg.addComponent(c);
}
}
hg.addGap(0, 0, Short.MAX_VALUE);
final JButton btn1 = isMac() ? cancelBtn : okBtn;
final JButton btn2 = isMac() ? okBtn : cancelBtn;
if (btn1 != null) {
hg.addComponent(btn1);
vg.addComponent(btn1);
}
if (btn2 != null) {
hg.addComponent(btn2);
vg.addComponent(btn2);
}
layout.setHorizontalGroup(hg);
layout.setVerticalGroup(vg);
if (okBtn != null && cancelBtn != null)
equalizeSize(okBtn, cancelBtn);
return panel;
}
Aggregations