下面列出了javax.swing.GroupLayout#linkSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @author Marian Petras
*/
static void layoutSelectResourcePanel(final Container thePanel,
final String instructionsText,
final String selectionLabelText,
final Component selectionComp,
final JButton button1,
final JButton button2) {
JTextArea instructions = new JTextArea();
JLabel lblSelection = new JLabel();
instructions.setColumns(20);
instructions.setEditable(false);
instructions.setLineWrap(true);
instructions.setText(instructionsText);
instructions.setWrapStyleWord(true);
instructions.setDisabledTextColor(new JLabel().getForeground());
instructions.setEnabled(false);
instructions.setOpaque(false);
lblSelection.setLabelFor(selectionComp);
Mnemonics.setLocalizedText(lblSelection, selectionLabelText);
JScrollPane scrollPane = new JScrollPane(selectionComp);
Container filesSelection = new JPanel();
GroupLayout layout = new GroupLayout(filesSelection);
filesSelection.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(LEADING)
.addComponent(lblSelection)
.addGroup(layout.createSequentialGroup()
.addComponent(scrollPane, 0, DEFAULT_SIZE, Integer.MAX_VALUE)
.addPreferredGap(RELATED)
.addGroup(layout.createParallelGroup(LEADING)
.addComponent(button1)
.addComponent(button2)))
);
layout.linkSize(SwingConstants.HORIZONTAL, button1, button2);
layout.setVerticalGroup(
layout.createParallelGroup(LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblSelection)
.addPreferredGap(RELATED)
.addGroup(layout.createParallelGroup(LEADING)
.addComponent(scrollPane, 0, DEFAULT_SIZE, Integer.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(button1)
.addPreferredGap(RELATED)
.addComponent(button2))))
);
LayoutStyle layoutStyle = layout.getLayoutStyle();
if (layoutStyle == null) {
layoutStyle = LayoutStyle.getInstance();
}
BorderLayout mainLayout = new BorderLayout();
thePanel.setLayout(mainLayout);
thePanel.add(instructions, BorderLayout.PAGE_START);
thePanel.add(filesSelection, BorderLayout.CENTER);
mainLayout.setVgap(layoutStyle.getPreferredGap(instructions,
lblSelection,
UNRELATED,
SwingConstants.NORTH,
thePanel));
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
// <editor-fold defaultstate="collapsed" desc="UI Initialization Code">
private void initComponents() {
contentsPanelPlaceholder = new JPanel(cardLayout);
if (withButtons) {
replaceButton = new JButton();
skipButton = new JButton();
ignoreButton = new JButton();
infoButton = new JButton();
cancelButton = new JButton();
helpButton = new JButton();
Mnemonics.setLocalizedText(replaceButton, bundle.getString("CTL_ReplaceButton")); // NOI18N
Mnemonics.setLocalizedText(skipButton, bundle.getString("CTL_SkipButton")); // NOI18N
Mnemonics.setLocalizedText(ignoreButton, bundle.getString("CTL_IgnoreButton")); // NOI18N
Mnemonics.setLocalizedText(infoButton, bundle.getString("CTL_InfoButton")); // NOI18N
Mnemonics.setLocalizedText(cancelButton, bundle.getString("CTL_CloseButton")); // NOI18N
Mnemonics.setLocalizedText(helpButton, bundle.getString("CTL_HelpButton")); // NOI18N
helpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
helpButtonActionPerformed(evt);
}
});
}
GroupLayout layout;
setLayout (layout = new GroupLayout(this));
GroupLayout.SequentialGroup horizGroup = layout.createSequentialGroup();
horizGroup.addContainerGap();
if (withButtons) {
horizGroup.addGroup(
layout.createParallelGroup(TRAILING)
.addComponent(contentsPanelPlaceholder)
.addGroup(layout.createSequentialGroup()
.addComponent(replaceButton)
.addPreferredGap(RELATED)
.addComponent(skipButton)
.addPreferredGap(RELATED)
.addComponent(ignoreButton)
.addPreferredGap(RELATED)
.addComponent(infoButton)
.addPreferredGap(RELATED)
.addComponent(cancelButton)
.addPreferredGap(RELATED)
.addComponent(helpButton)));
layout.linkSize(SwingConstants.HORIZONTAL, cancelButton,
helpButton,
infoButton,
replaceButton,
ignoreButton,
skipButton);
} else {
horizGroup.addComponent(contentsPanelPlaceholder);
}
horizGroup.addContainerGap();
layout.setHorizontalGroup(horizGroup);
GroupLayout.SequentialGroup vertGroup = layout.createSequentialGroup();
vertGroup.addContainerGap();
vertGroup.addComponent(contentsPanelPlaceholder);
if (withButtons) {
vertGroup
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(BASELINE)
.addComponent(helpButton)
.addComponent(cancelButton)
.addComponent(infoButton)
.addComponent(skipButton)
.addComponent(ignoreButton)
.addComponent(replaceButton));
}
vertGroup.addContainerGap();
layout.setVerticalGroup(vertGroup);
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form
* Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
testDirsLabel = new JLabel();
testDirsScrollPane = new JScrollPane();
testDirsList = new JList<BasePathSupport.Item>();
addFolderButton = new JButton();
removeButton = new JButton();
moveUpButton = new JButton();
moveDownButton = new JButton();
providersLabel = new JLabel();
providersPanel = new JPanel();
Mnemonics.setLocalizedText(testDirsLabel, NbBundle.getMessage(CustomizerTesting.class, "CustomizerTesting.testDirsLabel.text")); // NOI18N
testDirsScrollPane.setViewportView(testDirsList);
Mnemonics.setLocalizedText(addFolderButton, NbBundle.getMessage(CustomizerTesting.class, "CustomizerTesting.addFolderButton.text")); // NOI18N
Mnemonics.setLocalizedText(removeButton, NbBundle.getMessage(CustomizerTesting.class, "CustomizerTesting.removeButton.text")); // NOI18N
Mnemonics.setLocalizedText(moveUpButton, NbBundle.getMessage(CustomizerTesting.class, "CustomizerTesting.moveUpButton.text")); // NOI18N
Mnemonics.setLocalizedText(moveDownButton, NbBundle.getMessage(CustomizerTesting.class, "CustomizerTesting.moveDownButton.text")); // NOI18N
Mnemonics.setLocalizedText(providersLabel, NbBundle.getMessage(CustomizerTesting.class, "CustomizerTesting.providersLabel.text")); // NOI18N
GroupLayout providersPanelLayout = new GroupLayout(providersPanel);
providersPanel.setLayout(providersPanelLayout);
providersPanelLayout.setHorizontalGroup(
providersPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGap(0, 407, Short.MAX_VALUE)
);
providersPanelLayout.setVerticalGroup(
providersPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGap(0, 46, Short.MAX_VALUE)
);
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(providersPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(testDirsScrollPane)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(addFolderButton, GroupLayout.Alignment.TRAILING)
.addComponent(removeButton, GroupLayout.Alignment.TRAILING)
.addComponent(moveUpButton, GroupLayout.Alignment.TRAILING)
.addComponent(moveDownButton, GroupLayout.Alignment.TRAILING)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(testDirsLabel)
.addComponent(providersLabel))
.addGap(0, 0, Short.MAX_VALUE))
);
layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {addFolderButton, moveDownButton, moveUpButton, removeButton});
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(testDirsLabel)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(testDirsScrollPane, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(addFolderButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(removeButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(moveUpButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(moveDownButton)))
.addGap(18, 18, 18)
.addComponent(providersLabel)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(providersPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0))
);
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
includePathScrollPane = new JScrollPane();
includePathList = new JList<BasePathSupport.Item>();
addFolderButton = new JButton();
removeButton = new JButton();
moveUpButton = new JButton();
moveDownButton = new JButton();
includePathScrollPane.setViewportView(includePathList);
Mnemonics.setLocalizedText(addFolderButton, NbBundle.getMessage(CustomizerIncludePathInternal.class, "CustomizerIncludePathInternal.addFolderButton.text")); // NOI18N
Mnemonics.setLocalizedText(removeButton, NbBundle.getMessage(CustomizerIncludePathInternal.class, "CustomizerIncludePathInternal.removeButton.text")); // NOI18N
Mnemonics.setLocalizedText(moveUpButton, NbBundle.getMessage(CustomizerIncludePathInternal.class, "CustomizerIncludePathInternal.moveUpButton.text")); // NOI18N
Mnemonics.setLocalizedText(moveDownButton, NbBundle.getMessage(CustomizerIncludePathInternal.class, "CustomizerIncludePathInternal.moveDownButton.text")); // NOI18N
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(includePathScrollPane, GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(addFolderButton, GroupLayout.Alignment.TRAILING)
.addComponent(removeButton, GroupLayout.Alignment.TRAILING)
.addComponent(moveUpButton, GroupLayout.Alignment.TRAILING)
.addComponent(moveDownButton, GroupLayout.Alignment.TRAILING))
.addContainerGap())
);
layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {addFolderButton, moveDownButton, moveUpButton, removeButton});
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(addFolderButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(removeButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(moveUpButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(moveDownButton))
.addComponent(includePathScrollPane, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addContainerGap())
);
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form
* Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
testDirsLabel = new JLabel();
testDirsScrollPane = new JScrollPane();
testDirsList = new JList<BasePathSupport.Item>();
addFolderButton = new JButton();
removeButton = new JButton();
moveUpButton = new JButton();
moveDownButton = new JButton();
Mnemonics.setLocalizedText(testDirsLabel, NbBundle.getMessage(CustomizerSeleniumTesting.class, "CustomizerSeleniumTesting.testDirsLabel.text")); // NOI18N
testDirsScrollPane.setViewportView(testDirsList);
Mnemonics.setLocalizedText(addFolderButton, NbBundle.getMessage(CustomizerSeleniumTesting.class, "CustomizerSeleniumTesting.addFolderButton.text")); // NOI18N
Mnemonics.setLocalizedText(removeButton, NbBundle.getMessage(CustomizerSeleniumTesting.class, "CustomizerSeleniumTesting.removeButton.text")); // NOI18N
Mnemonics.setLocalizedText(moveUpButton, NbBundle.getMessage(CustomizerSeleniumTesting.class, "CustomizerSeleniumTesting.moveUpButton.text")); // NOI18N
Mnemonics.setLocalizedText(moveDownButton, NbBundle.getMessage(CustomizerSeleniumTesting.class, "CustomizerSeleniumTesting.moveDownButton.text")); // NOI18N
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(testDirsScrollPane, GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(addFolderButton, GroupLayout.Alignment.TRAILING)
.addComponent(removeButton, GroupLayout.Alignment.TRAILING)
.addComponent(moveUpButton, GroupLayout.Alignment.TRAILING)
.addComponent(moveDownButton, GroupLayout.Alignment.TRAILING)))
.addGroup(layout.createSequentialGroup()
.addComponent(testDirsLabel)
.addGap(0, 242, Short.MAX_VALUE))
);
layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {addFolderButton, moveDownButton, moveUpButton, removeButton});
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(testDirsLabel)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(testDirsScrollPane, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(addFolderButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(removeButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(moveUpButton)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(moveDownButton)))
.addContainerGap())
);
}
public FindBox(final MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
this.setHideOnEscapeButton();
JLabel label = new JLabel("Find What:");
textField = new JTextField();
RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea();
if (pane != null) {
textField.setText(pane.getSelectedText());
}
mcase = new JCheckBox("Match Case");
regex = new JCheckBox("Regex");
wholew = new JCheckBox("Whole Words");
reverse = new JCheckBox("Search Backwards");
wrap = new JCheckBox("Wrap");
findButton = new JButton("Find");
findButton.addActionListener(new FindButton());
this.getRootPane().setDefaultButton(findButton);
KeyStroke funcF3 = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0, false);
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(funcF3, "FindNext");
this.getRootPane().getActionMap().put("FindNext", new FindExploreAction(true));
KeyStroke sfuncF3 = KeyStroke.getKeyStroke(KeyEvent.VK_F3, InputEvent.SHIFT_DOWN_MASK, false);
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sfuncF3, "FindPrevious");
this.getRootPane().getActionMap().put("FindPrevious", new FindExploreAction(false));
mcase.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
regex.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
wholew.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
reverse.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
wrap.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Dimension center = new Dimension((int) (screenSize.width * 0.35),
Math.min((int) (screenSize.height * 0.20), 200));
final int x = (int) (center.width * 0.2);
final int y = (int) (center.height * 0.2);
this.setBounds(x, y, center.width, center.height);
this.setResizable(false);
GroupLayout layout = new GroupLayout(getRootPane());
getRootPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(label)
.addGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(textField)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(mcase)
.addComponent(wholew).addComponent(wrap))
.addGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(regex)
.addComponent(reverse))))
.addGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(findButton)));
layout.linkSize(SwingConstants.HORIZONTAL, findButton);
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(label).addComponent(textField)
.addComponent(findButton))
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(mcase)
.addComponent(regex))
.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(wholew)
.addComponent(reverse))
.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(wrap)))));
this.adjustWindowPositionBySavedState();
this.setSaveWindowPositionOnClosing();
this.setName("Find");
this.setTitle("Find");
this.setVisible(true);
}