下面列出了javax.swing.JButton#setToolTipText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Gets zoom button. */
private JButton getZoomButton(final int xf, final int yf) {
// PENDING buttons should have their own icons.
JButton button = new JButton(""+xf+":"+yf); // NOI18N
if (xf < yf)
button.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomOut") + " " + xf + " : " + yf);
else
button.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomIn") + " " + xf + " : " + yf);
button.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_Zoom_BTN"));
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
customZoom(xf, yf);
}
});
return button;
}
private void addFileNewButton(JToolBar buttonBar, Insets margin) {
JButton fileNew = new JButton( new ImageIcon(
GUIFrame.class.getResource("/resources/images/New-16.png")) );
fileNew.setMargin(margin);
fileNew.setFocusPainted(false);
fileNew.setToolTipText(formatToolTip("New (Ctrl+N)", "Starts a new model."));
fileNew.addActionListener( new ActionListener() {
@Override
public void actionPerformed( ActionEvent event ) {
GUIFrame.this.newModel();
controlStartResume.requestFocusInWindow();
}
} );
buttonBar.add( fileNew );
}
public AttributeFileValueCellEditor(ParameterTypeAttributeFile type) {
super(type);
button = new JButton(new ResourceAction(true, "edit_attributefile") {
private static final long serialVersionUID = 1L;
@Override
public void loggedActionPerformed(ActionEvent e) {
buttonPressed();
}
});
button.setMargin(new Insets(0, 0, 0, 0));
button.setToolTipText("Edit or create attribute description files and data (XML).");
addButton(button, GridBagConstraints.RELATIVE);
addButton(createFileChooserButton(), GridBagConstraints.REMAINDER);
}
private JPanel createHeaderPanel(String title, String type, boolean largePadding, ActionListener actionListener)
{
JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(new EmptyBorder(largePadding ? 11 : 0, 0, 0, 0));
panel.setBackground(ColorScheme.DARK_GRAY_COLOR);
JLabel headerLabel = new JLabel(title);
headerLabel.setForeground(Color.WHITE);
headerLabel.setFont(FontManager.getRunescapeSmallFont());
panel.add(headerLabel, BorderLayout.CENTER);
JButton addButton = new JButton(ADD_ICON);
addButton.setRolloverIcon(ADD_ICON_HOVER);
SwingUtil.removeButtonDecorations(addButton);
addButton.setPreferredSize(new Dimension(14, 14));
addButton.setToolTipText("Add a " + type);
addButton.addActionListener(actionListener);
panel.add(addButton, BorderLayout.EAST);
return panel;
}
private JButton createResetPinButton() {
resetPinButton = new JButton(i.get(Icons.RESET_PIN));
resetPinButton.setToolTipText(tr("main_reset_pin"));
resetPinButton.setVerticalAlignment(SwingConstants.CENTER);
resetPinButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Welcome welcome = new Welcome(Main.this, true);
welcome.setLocationRelativeTo(Main.this);
welcome.setVisible(true);
}
});
resetPinButton.setVisible(!Globals.getInstance().usingLedger());
return resetPinButton;
}
/**
* Método que cria o ToolTipText, adiciona a imagem, ActionListener, efeito(classe EfeitoBtn) e,
* por fim, adiciona o JButton na JToolBar (barraS)
* @param toolTipText String - ToolTipText que será exibido
* @param img String - caminho da imagem do JButton
* @param ev ActionListener - evento que será executado ao pressionar o botão
*/
private JButton configBtns(String toolTipText, String img, ActionListener ev) {
JButton btn = new JButton();
btn.setToolTipText(toolTipText);
btn.setIcon(new ImageIcon(getClass().getResource(img)));
btn.addActionListener(ev);
EfeitoBtn eb = new EfeitoBtn(btn);
barraS.add(btn);
return btn;
}
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;
}
private void initInstantiate()
{
// status
mName = new JLabel();
mName.setFont(mName.getFont().deriveFont(Font.BOLD));
mStatus = new JLabel();
// commands
mRun = new JButton("Run");
mRun.setToolTipText("Run current script");
mInsertHistory = new JButton("Insert History");
mInsertHistory.setToolTipText("Insert current history before selected point in script");
mLoadDisk = new JButton("Load...");
mLoadDisk.setToolTipText("Read a script from the disk");
mSaveDisk = new JButton("Save...");
mSaveDisk.setToolTipText("Save script to disk");
mClearScript = new JButton("Clear Script");
mClearScript.setToolTipText("Delete all lines from script");
// edits
mDelete = new JButton("Del");
mDelete.setToolTipText("Delete selected line from script");
mMoveUp = new JButton("\u2191");
mMoveUp.setToolTipText("Move selected lines up");
mMoveDown = new JButton("\u2193");
mMoveDown.setToolTipText("Move selected lines down");
mRename = new JButton("Rename");
mRename.setToolTipText("Rename script");
mEditExpected = new JButton("Edit");
mEditExpected.setToolTipText("Edit expected text");
mToggleExpectation = new JButton("Toggle");
mToggleExpectation.setToolTipText("Toggle if expected text is pass/fail/don't care");
mUpdateExpected = new JButton("Update");
mUpdateExpected.setToolTipText("Update expected with actual");
mClearResults = new JButton("Clear Results");
mClearResults.setToolTipText("Clear results");
mScript = new JList<ScriptTransactionBean>(new ScriptModel(mRuntime));
mScript.setCellRenderer(new ScriptCellRenderer());
}
private void buildContent() {
// create buttons:
buttonSkip = new JButton(ImageLoadingUtil.SKIP.createHighDpiImageIcon());
buttonRotateLeft = new JButton(ImageLoadingUtil.LEFT.createHighDpiImageIcon());
buttonRotateRight = new JButton(ImageLoadingUtil.RIGHT.createHighDpiImageIcon());
// set tool tips:
buttonSkip.setToolTipText("Don't place tile and skip turn");
buttonRotateLeft.setToolTipText("Rotate left");
buttonRotateRight.setToolTipText("Rotate right");
// set listeners:
buttonSkip.addMouseListener((MouseClickListener) event -> controller.requestSkip());
buttonRotateLeft.addMouseListener((MouseClickListener) event -> rotateLeft());
buttonRotateRight.addMouseListener((MouseClickListener) event -> rotateRight());
// set constraints:
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.NONE;
// add buttons:
dialogPanel.add(buttonRotateLeft, constraints);
dialogPanel.add(buttonSkip, constraints);
dialogPanel.add(buttonRotateRight, constraints);
// change constraints and add label:
constraints.fill = GridBagConstraints.VERTICAL;
constraints.gridy = 1;
constraints.gridwidth = 3;
ImageIcon defaultImage = new Tile(TileType.Null).getScaledIcon(50);
tileLabels = new ArrayList<>();
tiles = new ArrayList<>();
for (int i = 0; i < GameSettings.MAXIMAL_TILES_ON_HAND; i++) {
JLabel label = new JLabel(defaultImage);
tileLabels.add(label);
constraints.gridy++;
final int index = i;
label.addMouseListener((MouseClickListener) event -> selectTileLabel(index));
dialogPanel.add(label, constraints);
}
constraints.gridy++;
dialogPanel.add(Box.createVerticalStrut(BOTTOM_SPACE), constraints);
}
private JButton createHyperlinkButton(String linkText, String tooltip) {
JButton button = new JButton(String.format("<html><body><font color=\"#000099\"><u>%s</u></font></body></html>", linkText));
button.setFocusPainted(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.setContentAreaFilled(false);
button.setBorderPainted(false);
button.setOpaque(false);
button.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
button.setBackground(Color.white);
button.addActionListener(this);
UIUtilities.setToPreferredSizeOnly(button);
add(button);
return button;
}
public static JButton createOpenFileButton(String toolTip) {
JButton button = new JButton();
button.setText("");
button.setToolTipText(toolTip);
button.setIcon(new ImageIcon(JPlagCreator.class.getResource("/atujplag/data/open.gif")));
button.setPreferredSize(new java.awt.Dimension(24, 24));
button.setBackground(JPlagCreator.SYSTEMCOLOR);
return button;
}
public PreviewValueCellEditor(ParameterTypePreview type) {
this.type = type;
button = new JButton("Show Preview...");
button.setToolTipText(type.getDescription());
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
buttonPressed();
}
});
}
private void tuneNotesButton(JButton tempJB, String notes) {
if (notes.length() == 0) {
tempJB.setFont(new Font("SansSerif", Font.PLAIN, 11));
} else {
tempJB.setFont(new Font("SansSerif", Font.BOLD, 11));
}
tempJB.setToolTipText(notes);
}
private JButton createButton(String action) {
JButton btn = new JButton();
btn.setActionCommand(action);
btn.setToolTipText(action);
btn.setIcon(Utils.getIconByResourceName("/ui/resources/main/" + action.replace(" ", "")));
btn.addActionListener(sActionListener);
return btn;
}
private JButton createZoomOrigButton() {
JButton origButton = new JButton(NbBundle.getMessage(ScreenshotComponent.class, "LBL_ZoomOrig"));
origButton.setToolTipText(NbBundle.getMessage(ScreenshotComponent.class, "TLTP_ZoomOrig"));
origButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ScreenshotComponent.class, "LBL_ZoomOrigA11yDescr"));
origButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
canvas.zoom(1);
}
});
origButton.setAlignmentX(CENTER_ALIGNMENT);
return origButton;
}
public MethodCodePanel(DecompiledEditorPane decompiledEditor) {
sourceTextArea = new ASMSourceEditorPane(decompiledEditor);
setLayout(new BorderLayout());
docsPanel = new DocsPanel();
sourceTextArea.addDocsListener(docsPanel);
add(new JPersistentSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(sourceTextArea), new JScrollPane(docsPanel), Configuration.guiAvm2DocsSplitPaneDividerLocationPercent));
sourceTextArea.changeContentType("text/flasm3");
sourceTextArea.setFont(Configuration.getSourceFont());
buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
JButton graphButton = new JButton(View.getIcon("graph16"));
graphButton.addActionListener(this::graphButtonActionPerformed);
graphButton.setToolTipText(AppStrings.translate("button.viewgraph"));
graphButton.setMargin(new Insets(3, 3, 3, 3));
hexButton = new JToggleButton(View.getIcon("hexas16"));
hexButton.addActionListener(this::hexButtonActionPerformed);
hexButton.setToolTipText(AppStrings.translate("button.viewhexpcode"));
hexButton.setMargin(new Insets(3, 3, 3, 3));
hexOnlyButton = new JToggleButton(View.getIcon("hex16"));
hexOnlyButton.addActionListener(this::hexOnlyButtonActionPerformed);
hexOnlyButton.setToolTipText(AppStrings.translate("button.viewhex"));
hexOnlyButton.setMargin(new Insets(3, 3, 3, 3));
NoneSelectedButtonGroup exportModeButtonGroup = new NoneSelectedButtonGroup();
exportModeButtonGroup.add(hexButton);
exportModeButtonGroup.add(hexOnlyButton);
buttonsPanel.add(graphButton);
buttonsPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonsPanel.add(hexButton);
buttonsPanel.add(hexOnlyButton);
buttonsPanel.add(new JPanel());
add(buttonsPanel, BorderLayout.NORTH);
}
/** Constructs a UI component for the UnitScroller. */
public Component build() {
final JPanel panel = new JPanel();
collapsiblePanel = new CollapsiblePanel(panel, "");
updateMovesLeft();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(selectUnitImagePanel);
panel.add(territoryNameLabel);
panel.add(Box.createVerticalStrut(2));
final JButton prevUnit = new JButton(UnitScrollerIcon.LEFT_ARROW.get());
prevUnit.setToolTipText(PREVIOUS_UNITS_TOOLTIP);
prevUnit.setAlignmentX(JComponent.CENTER_ALIGNMENT);
prevUnit.addActionListener(e -> centerOnPreviousMovableUnit());
final JButton sleepButton = new JButton(UnitScrollerIcon.SLEEP.get());
sleepButton.setToolTipText(SLEEP_UNITS_TOOLTIP);
sleepButton.addActionListener(e -> sleepCurrentUnits());
final JButton skipButton = new JButton(UnitScrollerIcon.SKIP.get());
skipButton.setToolTipText(SKIP_UNITS_TOOLTIP);
skipButton.addActionListener(e -> skipCurrentUnits());
final JButton wakeAllButton = new JButton(UnitScrollerIcon.WAKE_ALL.get());
wakeAllButton.setToolTipText(WAKE_ALL_TOOLTIP);
wakeAllButton.addActionListener(e -> wakeAllUnits());
wakeAllButton.setFocusable(false);
final JButton nextUnit = new JButton(UnitScrollerIcon.RIGHT_ARROW.get());
nextUnit.setToolTipText(NEXT_UNITS_TOOLTIP);
nextUnit.addActionListener(e -> centerOnNextMovableUnit());
final JPanel skipAndSleepPanel =
new JPanelBuilder()
.boxLayoutHorizontal()
.add(prevUnit)
.addHorizontalStrut(HORIZONTAL_BUTTON_GAP)
.add(wakeAllButton)
.addHorizontalStrut(HORIZONTAL_BUTTON_GAP)
.add(sleepButton)
.addHorizontalStrut(HORIZONTAL_BUTTON_GAP)
.add(skipButton)
.addHorizontalStrut(HORIZONTAL_BUTTON_GAP)
.add(nextUnit)
.build();
skipAndSleepPanel.setAlignmentX(JComponent.CENTER_ALIGNMENT);
panel.add(skipAndSleepPanel, BorderLayout.SOUTH);
panel.add(Box.createVerticalStrut(3));
return collapsiblePanel;
}
public ButtonHtmlDemo() {
ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
ImageIcon rightButtonIcon = createImageIcon("images/left.gif");
b1 = new JButton("<html><center><b><u>D</u>isable</b><br>" + "<font color=#ffffdd>middle button</font>", leftButtonIcon);
Font font = b1.getFont().deriveFont(Font.PLAIN);
b1.setFont(font);
b1.setVerticalTextPosition(AbstractButton.CENTER);
b1.setHorizontalTextPosition(AbstractButton.LEADING); // aka LEFT, for
// left-to-right
// locales
b1.setMnemonic(KeyEvent.VK_D);
b1.setActionCommand("disable");
b2 = new JButton("middle button", middleButtonIcon);
b2.setFont(font);
b2.setForeground(new Color(0xffffdd));
b2.setVerticalTextPosition(AbstractButton.BOTTOM);
b2.setHorizontalTextPosition(AbstractButton.CENTER);
b2.setMnemonic(KeyEvent.VK_M);
b3 = new JButton("<html><center><b><u>E</u>nable</b><br>" + "<font color=#ffffdd>middle button</font>", rightButtonIcon);
b3.setFont(font);
// Use the default text position of CENTER, TRAILING (RIGHT).
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enable");
b3.setEnabled(false);
// Listen for actions on buttons 1 and 3.
b1.addActionListener(this);
b3.addActionListener(this);
b1.setToolTipText("Click this button to disable the middle button.");
b2.setToolTipText("This middle button does nothing when you click it.");
b3.setToolTipText("Click this button to enable the middle button.");
// Add Components to this container, using the default FlowLayout.
add(b1);
add(b2);
add(b3);
}
/** Creates toolbar. */
private JToolBar createToolBar() {
// Definition of toolbar.
JToolBar toolBar = new JToolBar();
toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); //NOI18N
toolBar.setFloatable (false);
toolBar.setName (NbBundle.getBundle(ImageViewer.class).getString("ACSN_Toolbar"));
toolBar.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_Toolbar"));
JButton outButton = new JButton(SystemAction.get(ZoomOutAction.class));
outButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomOut"));
outButton.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_Out_BTN_Mnem").charAt(0));
outButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_Out_BTN"));
outButton.setText("");
toolBar.add(outButton);
toolbarButtons.add(outButton);
JButton inButton = new JButton(SystemAction.get(ZoomInAction.class));
inButton.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomIn"));
inButton.setMnemonic(NbBundle.getBundle(ImageViewer.class).getString("ACS_In_BTN_Mnem").charAt(0));
inButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACSD_In_BTN"));
inButton.setText("");
toolBar.add(inButton);
toolbarButtons.add(inButton);
toolBar.addSeparator(new Dimension(11, 0));
JButton button;
toolBar.add(button = getZoomButton(1,1));
toolbarButtons.add(button);
toolBar.addSeparator(new Dimension(11, 0));
toolBar.add(button = getZoomButton(1,3));
toolbarButtons.add(button);
toolBar.add(button = getZoomButton(1,5));
toolbarButtons.add(button);
toolBar.add(button = getZoomButton(1,7));
toolbarButtons.add(button);
toolBar.addSeparator(new Dimension(11, 0));
toolBar.add(button = getZoomButton(3,1));
toolbarButtons.add(button);
toolBar.add(button = getZoomButton(5,1));
toolbarButtons.add(button);
toolBar.add(button = getZoomButton(7,1));
toolbarButtons.add(button);
toolBar.addSeparator(new Dimension(11, 0));
// SystemAction sa = SystemAction.get(CustomZoomAction.class);
// sa.putValue (Action.SHORT_DESCRIPTION, NbBundle.getBundle(ImageViewer.class).getString("LBL_CustomZoom"));
toolBar.add (button = getZoomButton ());
toolbarButtons.add(button);
toolBar.addSeparator(new Dimension(11, 0));
toolBar.add(button = getGridButton());
toolbarButtons.add(button);
// Image Dimension
toolBar.addSeparator(new Dimension(11, 0));
toolBar.add(new JLabel(NbBundle.getMessage(ImageViewer.class, "LBL_ImageDimensions", imageWidth, imageHeight)));
// Image File Size in KB, MB
if (imageSize != -1) {
toolBar.addSeparator(new Dimension(11, 0));
double kb = 1024.0;
double mb = kb * kb;
final double size;
final String label;
if (imageSize >= mb) {
size = imageSize / mb;
label = "LBL_ImageSizeMb"; // NOI18N
} else if (imageSize >= kb) {
size = imageSize / kb;
label = "LBL_ImageSizeKb"; // NOI18N
} else {
size = imageSize;
label = "LBL_ImageSizeBytes"; //NOI18N
}
toolBar.add(new JLabel(NbBundle.getMessage(ImageViewer.class, label, formatter.format(size))));
}
for (JButton jb : toolbarButtons) {
jb.setFocusable(false);
}
return toolBar;
}
@Override
protected void addCustomComponents(@Nonnull final JPanel panel,
@Nonnull final GridBagConstraints gbdata) {
final JButton buttonClipboardText = new JButton(ICON_PLANTUML);
buttonClipboardText.setName("BUTTON.PLANTUML");
buttonClipboardText.setToolTipText("Copy formed PlantUML script to clipboard");
buttonClipboardText.addActionListener((ActionEvent e) -> {
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(new StringSelection(preprocessEditorText(editor.getText())), null);
});
checkBoxGroupTopics = new JCheckBox("Group topics ", this.modeGroupTopics);
checkBoxGroupTopics.setName(PROPERTY_TOPICS_GROUP);
checkBoxGroupTopics.setToolTipText("Group all topics on scheme together");
checkBoxGroupTopics.addActionListener((x) -> {
this.onConfigCheckboxChange(checkBoxGroupTopics);
});
checkBoxGroupStores = new JCheckBox("Group stores ", this.modeGroupStores);
checkBoxGroupStores.setName(PROPERTY_STORE_GROUP);
checkBoxGroupStores.setToolTipText("Group all stores on scheme together");
checkBoxGroupStores.addActionListener((x) -> {
this.onConfigCheckboxChange(checkBoxGroupStores);
});
checkBoxOrtho = new JCheckBox("Orthogonal lines ", this.modeOrtho);
checkBoxOrtho.setName(PROPERTY_ORTHOGONAL);
checkBoxOrtho.setToolTipText("Orthogonal connector lines");
checkBoxOrtho.addActionListener((x) -> {
this.onConfigCheckboxChange(checkBoxOrtho);
});
checkBoxHorizontal = new JCheckBox("Horizontal layout ", this.modeHoriz);
checkBoxHorizontal.setName(PROPERTY_LAYOUT_HORIZ);
checkBoxHorizontal.setToolTipText("Horizontal layouting of components");
checkBoxHorizontal.addActionListener((x) -> {
this.onConfigCheckboxChange(checkBoxHorizontal);
});
panel.add(buttonClipboardText, gbdata);
panel.add(checkBoxGroupTopics, gbdata);
panel.add(checkBoxGroupStores, gbdata);
panel.add(checkBoxOrtho, gbdata);
panel.add(checkBoxHorizontal, gbdata);
}