下面列出了javax.swing.JButton#setMargin ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public JPanel getMarkerPairComponent(MarkerPair markerPair, int measurementIndex, int markerPairIndex) {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.setBorder(markerPairControlsBorder);
panel.setAlignmentX(0);
// Markers
panel.add(getMarkerComponent(markerPair.getMarkerName(0), measurementIndex, markerPairIndex, 0));
panel.add(getMarkerComponent(markerPair.getMarkerName(1), measurementIndex, markerPairIndex, 1));
// Delete marker pair button
JButton removeMarkerPairButton = new JButton(new RemoveMarkerPairAction(measurementIndex, markerPairIndex));
removeMarkerPairButton.setRolloverIcon(removeRolloverIcon);
removeMarkerPairButton.setMargin(new Insets(0,0,0,0));
removeMarkerPairButton.setMinimumSize(buttonDim);
removeMarkerPairButton.setMaximumSize(buttonDim);
removeMarkerPairButton.setPreferredSize(buttonDim);
removeMarkerPairButton.setBorder(null);
removeMarkerPairButton.setContentAreaFilled(false);
removeMarkerPairButton.setOpaque(true);
removeMarkerPairButton.setBackground(Color.white);
panel.add(removeMarkerPairButton);
return panel;
}
/**
* Creates a button that zooms the drawing to a scale factor so that
* it fits the window size.
*
* @return The created button.
*/
private JButton zoomViewToWindowButton(final OpenTCSDrawingView drawingView) {
final JButton button = new JButton();
button.setToolTipText(
labels.getString("drawingViewPlacardPanel.button_zoomViewToWindow.tooltipText")
);
button.setIcon(ImageDirectory.getImageIcon("/menu/zoom-fit-best-4.png"));
button.setMargin(new Insets(0, 0, 0, 0));
button.setFocusable(false);
button.addActionListener((ActionEvent e) -> drawingView.zoomViewToWindow());
return button;
}
private void addFileSaveButton(JToolBar buttonBar, Insets margin) {
fileSave = new JButton( new ImageIcon(
GUIFrame.class.getResource("/resources/images/Save-16.png")) );
fileSave.setMargin(margin);
fileSave.setFocusPainted(false);
fileSave.setToolTipText(formatToolTip("Save (Ctrl+S)", "Saves the present model."));
fileSave.setEnabled(false);
fileSave.addActionListener( new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
GUIFrame.this.save();
controlStartResume.requestFocusInWindow();
}
} );
buttonBar.add( fileSave );
}
/**
* Creates a new {@link FilterValueCellEditor} instance.
*/
public FilterValueCellEditor(final ParameterTypeFilter type) {
button = new JButton(new ResourceAction(true, "set_filters") {
private static final long serialVersionUID = 8274776396885048377L;
@Override
public void loggedActionPerformed(ActionEvent e) {
dialog = new FilterPropertyDialog(operator, type, "filter");
dialog.setVisible(true);
// no dialog handling necessary, does everything itself
fireEditingStopped();
}
});
button.setMargin(new Insets(0, 0, 0, 0));
}
private JButton makeButton(SpinIcon.Type type) {
SpinIcon icon = new SpinIcon(type);
JButton butt = new JButton(icon);
Insets i = new Insets(0, 0, 0, 0);
butt.setMargin(i);
butt.setBorderPainted(false);
butt.setFocusPainted(false);
butt.setPreferredSize(new Dimension(icon.getIconWidth() + 2, icon.getIconHeight() + 2));
return butt;
}
private JButton createButton(String label, Font fntButton, Insets marginButton, Rectangle bounds, ActionListener listener) {
JButton btnNumberOne = new JButton(label);
btnNumberOne.setMargin(marginButton);
btnNumberOne.setFont(fntButton);
btnNumberOne.setBounds(bounds);
btnNumberOne.addActionListener(listener);
return btnNumberOne;
}
private JButton createButton(String label, Font fntButton, Insets marginButton, Rectangle bounds, ActionListener listener) {
JButton btnNumberOne = new JButton(label);
btnNumberOne.setMargin(marginButton);
btnNumberOne.setFont(fntButton);
btnNumberOne.setBounds(bounds);
btnNumberOne.addActionListener(listener);
return btnNumberOne;
}
public void addButton(String image, double amount) {
JButton btn = new JButton();
btn.setIcon(new ImageIcon(tnbbutton.getThumbNailText(dlSystem.getResourceAsImage(image), Formats.CURRENCY.formatValue(amount))));
btn.setFocusPainted(false);
btn.setFocusable(false);
btn.setRequestFocusEnabled(false);
btn.setHorizontalTextPosition(SwingConstants.CENTER);
btn.setVerticalTextPosition(SwingConstants.BOTTOM);
btn.setMargin(new Insets(2, 2, 2, 2));
btn.addActionListener(new AddAmount(amount));
jPanel6.add(btn);
}
/**
* Returns a panel of buttons, each button representing a day in the month. This is a
* sub-component of the DatePanel.
*
* @return the panel.
*/
private JPanel getCalendarPanel() {
final JPanel panel = new JPanel(new GridLayout(7, 7));
panel.add(new JLabel("Sun", SwingConstants.CENTER));
panel.add(new JLabel("Mon", SwingConstants.CENTER));
panel.add(new JLabel("Tue", SwingConstants.CENTER));
panel.add(new JLabel("Wed", SwingConstants.CENTER));
panel.add(new JLabel("Thu", SwingConstants.CENTER));
panel.add(new JLabel("Fri", SwingConstants.CENTER));
panel.add(new JLabel("Sat", SwingConstants.CENTER));
this.buttons = new JButton[42];
for (int i = 0; i < 42; i++) {
final JButton button = new JButton("");
button.setMargin(new Insets(1, 1, 1, 1));
button.setName(Integer.toString(i));
button.setFont(this.dateFont);
button.setFocusPainted(false);
button.setActionCommand("dateButtonClicked");
button.addActionListener(this);
this.buttons[i] = button;
panel.add(button);
}
return panel;
}
/**
* Create a new InternalWindow.
*
* @param title title text
*/
InternalWindow(String title) {
setLayout(new BorderLayout());
titleBar = new TitleBar();
add(titleBar, BorderLayout.NORTH);
titleBar.setLayout(new SBoxLayout(SBoxLayout.HORIZONTAL, TITLEBAR_PADDING));
titleLabel = new JLabel();
setTitle(title);
// Squeeze the label if there's not enough space
titleLabel.setMinimumSize(new Dimension(0, 0));
titleBar.add(titleLabel);
SBoxLayout.addSpring(titleBar);
// Add the close and minimize buttons
minimizeButton = new JButton(minimizeIcon);
minimizeButton.setMargin(new Insets(0, 0, 0, 0));
minimizeButton.setBorder(BorderFactory.createEmptyBorder());
minimizeButton.setFocusable(false);
minimizeButton.addActionListener(new MinimizeListener());
titleBar.add(minimizeButton);
closeButton = new JButton(closeIcon);
closeButton.setMargin(new Insets(0, 0, 0, 0));
closeButton.setBorder(BorderFactory.createEmptyBorder());
closeButton.setFocusable(false);
closeButton.addActionListener(new CloseActionListener());
titleBar.add(closeButton);
cache = new ComponentPaintCache(this);
}
private static void setupBrowseButton(JButton button) {
Insets margin = button.getMargin();
if (margin.left > 4) {
margin.left = 4;
margin.right = 4;
button.setMargin(margin);
}
}
private JPanel controller() {
JPanel panel = new JPanel(new GridLayout(3, 1));
panel.setOpaque(false);
JPanel idxPath = new JPanel(new FlowLayout(FlowLayout.LEADING));
idxPath.setOpaque(false);
idxPath.add(new JLabel(MessageUtils.getLocalizedMessage("checkidx.label.index_path")));
JLabel idxPathLbl = new JLabel(lukeState.getIndexPath());
idxPathLbl.setToolTipText(lukeState.getIndexPath());
idxPath.add(idxPathLbl);
panel.add(idxPath);
JPanel results = new JPanel(new GridLayout(2, 1));
results.setOpaque(false);
results.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
results.add(new JLabel(MessageUtils.getLocalizedMessage("checkidx.label.results")));
results.add(resultLbl);
panel.add(results);
JPanel execButtons = new JPanel(new FlowLayout(FlowLayout.TRAILING));
execButtons.setOpaque(false);
JButton checkBtn = new JButton(FontUtils.elegantIconHtml("", MessageUtils.getLocalizedMessage("checkidx.button.check")));
checkBtn.setFont(StyleConstants.FONT_BUTTON_LARGE);
checkBtn.setMargin(new Insets(3, 0, 3, 0));
checkBtn.addActionListener(listeners::checkIndex);
execButtons.add(checkBtn);
JButton closeBtn = new JButton(MessageUtils.getLocalizedMessage("button.close"));
closeBtn.setFont(StyleConstants.FONT_BUTTON_LARGE);
closeBtn.setMargin(new Insets(3, 0, 3, 0));
closeBtn.addActionListener(e -> dialog.dispose());
execButtons.add(closeBtn);
panel.add(execButtons);
return panel;
}
protected void buildBelowDetailsPanel() {
Insets small = new Insets( 1, 1, 1, 1 );
lblChanges = new JLabel( "Changes: " );
btnSaveChanges = new JButton( "Save" );
// btnSaveChanges.setMnemonic( java.awt.event.KeyEvent.VK_ENTER );
btnSaveChanges.getInputMap( btnSaveChanges.WHEN_IN_FOCUSED_WINDOW )
.put( KeyStroke.getKeyStroke( CPSGlobalSettings.getModifierKey() + " ENTER" ), "save" );
btnSaveChanges.getActionMap().put( "save",
new AbstractAction() {
public void actionPerformed(ActionEvent e) {
btnSaveChanges.doClick();
}
});
btnDiscardChanges = new JButton( "Discard" );
btnSaveChanges.addActionListener( this );
btnDiscardChanges.addActionListener( this );
btnSaveChanges.setMargin( small );
btnDiscardChanges.setMargin( small );
initBelowDetailsPanel();
jplBelowDetails.add( lblStatus );
jplBelowDetails.add( Box.createHorizontalGlue() );
jplBelowDetails.add( lblChanges );
jplBelowDetails.add( btnSaveChanges );
jplBelowDetails.add( btnDiscardChanges );
}
/**
* Set preferences to Menu button.
*
* @param button
* @param foregroundColor
* @param backgroundColor
* @param font
* @return
*/
private JButton initMenuButton(JButton button, Color foregroundColor, Color backgroundColor, Font font) {
button.setBackground(backgroundColor);
button.setForeground(foregroundColor);
button.setBorderPainted(false);
button.setFocusPainted(false);
button.setHorizontalTextPosition(SwingConstants.CENTER);
button.setVerticalTextPosition(SwingConstants.BOTTOM);
button.setFont(font);
button.setMargin(new Insets(2, 16, 2, 16));
button.setOpaque(true);
button.setDoubleBuffered(true);
button.setRolloverEnabled(true);
return button;
}
public static JButton createButton (Icon icon, String tooltip) {
final JButton button = new JButton(icon);
// ensure small size, just for the icon
Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
button.setPreferredSize(size);
button.setMargin(new Insets(1, 1, 1, 1));
button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button)));
button.setToolTipText(tooltip);
button.setFocusable(false);
return button;
}
private JPanel content() {
JPanel panel = new JPanel(new BorderLayout());
panel.setOpaque(false);
panel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
JPanel header = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
header.setOpaque(false);
header.add(new JLabel(MessageUtils.getLocalizedMessage("documents.stored.label.stored_value")));
header.add(new JLabel(field));
panel.add(header, BorderLayout.PAGE_START);
JTextArea valueTA = new JTextArea(value);
valueTA.setLineWrap(true);
valueTA.setEditable(false);
valueTA.setBackground(Color.white);
JScrollPane scrollPane = new JScrollPane(valueTA);
panel.add(scrollPane, BorderLayout.CENTER);
JPanel footer = new JPanel(new FlowLayout(FlowLayout.TRAILING, 5, 5));
footer.setOpaque(false);
JButton copyBtn = new JButton(FontUtils.elegantIconHtml("", MessageUtils.getLocalizedMessage("button.copy")));
copyBtn.setMargin(new Insets(3, 3, 3, 3));
copyBtn.addActionListener(e -> {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection selection = new StringSelection(value);
clipboard.setContents(selection, null);
});
footer.add(copyBtn);
JButton closeBtn = new JButton(MessageUtils.getLocalizedMessage("button.close"));
closeBtn.setMargin(new Insets(3, 3, 3, 3));
closeBtn.addActionListener(e -> dialog.dispose());
footer.add(closeBtn);
panel.add(footer, BorderLayout.PAGE_END);
return panel;
}
private JButton createButton(String textResource, String iconName, String toolTipResource, ActionListener actionListener, boolean repeat) {
String text = textResource == null ? "" : mainPanel.translate(textResource);
JButton button = repeat ? new JRepeatButton(text, View.getIcon(iconName)) : new JButton(text, View.getIcon(iconName));
button.setMargin(new Insets(3, 3, 3, 10));
button.addActionListener(actionListener);
if (toolTipResource != null) {
button.setToolTipText(mainPanel.translate(toolTipResource));
}
return button;
}
protected void installComponents() {
field = new JFormattedTextField(createFormatterFactory());
field.setValue(peer.getDate());
field.setFocusLostBehavior(peer.getFocusLostBehavior());
field.setEditable(peer.isFieldEditable());
field.setToolTipText(peer.getToolTipText());
// button
button = new JButton();
button.setFocusable(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.setToolTipText(peer.getToolTipText());
setSimpeLook(false);
// calendar
calendarPane = new CalendarPane(peer.getStyle());
calendarPane.setShowTodayButton(peer.isShowTodayButton());
calendarPane.setFocusLostBehavior(JFormattedTextField.REVERT);
calendarPane.setFocusCycleRoot(true);
calendarPane.setBorder(BorderFactory.createEmptyBorder(1, 3, 0, 3));
calendarPane.setStripTime(false);
calendarPane.setLocale(peer.getLocale());
calendarPane.setZone(peer.getZone());
calendarPane.setFocusable(peer.isDropdownFocusable());
calendarPane.setColorOverrideMap(peer.getColorOverrideMap());
// popup
popup = new JPopupMenu();
popup.setLayout(new BorderLayout());
popup.add(calendarPane, BorderLayout.CENTER);
popup.setLightWeightPopupEnabled(true);
// add
peer.setLayout(new BorderLayout());
switch (peer.getPickerStyle()) {
case DatePicker.PICKER_STYLE_FIELD_AND_BUTTON:
peer.add(field, BorderLayout.CENTER);
peer.add(button, BorderLayout.EAST);
break;
case DatePicker.PICKER_STYLE_BUTTON:
peer.add(button, BorderLayout.EAST);
break;
}
peer.revalidate();
peer.repaint();
componentListener = new ComponentListener();
button.addActionListener(componentListener);
field.addPropertyChangeListener(componentListener);
calendarPane.addPropertyChangeListener(componentListener);
calendarPane.addCommitListener(componentListener);
calendarPane.addActionListener(componentListener);
peerDateChanged(peer.getDate());
}
JButton createButton(String name){
JButton button=new JButton(name);
button.setMargin(new Insets(0,5,0,5));
button.setFocusPainted(false);
return button;
}
protected void initGuiComponents() {
getContentPane().setLayout(
new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
getContentPane().add(Box.createVerticalStrut(5));
Box hBox = Box.createHorizontalBox();
hBox.add(Box.createHorizontalStrut(6));
hBox.add(new JLabel("Find:"));
hBox.add(Box.createHorizontalStrut(6));
hBox.add(patternTextField = new JTextField(20));
hBox.add(Box.createHorizontalStrut(3));
JButton helpRegExpButton = new JButton("?");
helpRegExpButton.setMargin(new Insets(0, 2, 0, 2));
helpRegExpButton.setToolTipText("GATE search expression builder.");
hBox.add(helpRegExpButton);
hBox.add(Box.createHorizontalGlue());
hBox.add(Box.createHorizontalStrut(6));
hBox.add(Box.createHorizontalGlue());
getContentPane().add(hBox);
getContentPane().add(Box.createVerticalStrut(5));
hBox = Box.createHorizontalBox();
hBox.add(Box.createHorizontalStrut(6));
hBox.add(ignoreCaseChk = new JCheckBox("Ignore case", true));
hBox.add(Box.createHorizontalStrut(6));
hBox.add(wholeWordsChk = new JCheckBox("Whole word", false));
hBox.add(Box.createHorizontalStrut(6));
hBox.add(regularExpressionChk = new JCheckBox("Regular Exp.", false));
regularExpressionChk.setToolTipText("Regular expression search.");
hBox.add(Box.createHorizontalStrut(6));
hBox.add(highlightsChk = new JCheckBox("Highlights", false));
highlightsChk
.setToolTipText("Restrict the search on the highlighted annotations.");
hBox.add(Box.createHorizontalStrut(6));
hBox.add(Box.createHorizontalGlue());
getContentPane().add(hBox);
getContentPane().add(Box.createVerticalStrut(5));
hBox = Box.createHorizontalBox();
hBox.add(Box.createHorizontalGlue());
JButton findFirstButton = new JButton(findFirstAction);
hBox.add(findFirstButton);
hBox.add(Box.createHorizontalStrut(6));
hBox.add(new JButton(findNextAction));
hBox.add(Box.createHorizontalStrut(6));
hBox.add(new JButton(cancelAction));
hBox.add(Box.createHorizontalGlue());
getContentPane().add(hBox);
getContentPane().add(Box.createVerticalStrut(5));
getRootPane().setDefaultButton(findFirstButton);
helpRegExpButton.addActionListener(new SearchExpressionsAction(
patternTextField, this, regularExpressionChk));
}