下面列出了javax.swing.JLabel#addMouseListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public IntroPanel() {
setLayout(null);
setOpaque(false);
introImage = new JLabel(new ImageIcon(
SwingSet3.class.getResource("resources/images/home_notext.png")));
introImage.setVerticalAlignment(JLabel.TOP);
introText = new SlidingLabel(new ImageIcon(
SwingSet3.class.getResource("resources/images/home_text.png")));
introText.setVisible(false);
introImage.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
slideTextIn();
}
});
add(introText);
add(introImage);
}
private void init() {
this.setLayout(new FlowLayout(
FlowLayout.LEADING, 0, 0));
setLinkLikeButton(button);
leftParenthesis = new JLabel("("); //NOI18N
rightParenthesis = new JLabel(")"); //NOI18N
add(leftParenthesis);
add(button);
add(rightParenthesis);
MouseListener ml = createLabelMouseListener();
leftParenthesis.addMouseListener(ml);
rightParenthesis.addMouseListener(ml);
button.setEnabled(false);
this.setMaximumSize(
this.getPreferredSize());
}
/**
* Creates bug summary component. If obj is a string will create a JLabel
* with that string as it's text and return it. If obj is an annotation will
* return a JLabel with the annotation's toString(). If that annotation is a
* SourceLineAnnotation or has a SourceLineAnnotation connected to it and
* the source file is available will attach a listener to the label.
*/
public Component bugSummaryComponent(String str, BugInstance bug) {
JLabel label = new JLabel();
label.setFont(label.getFont().deriveFont(Driver.getFontSize()));
label.setFont(label.getFont().deriveFont(Font.PLAIN));
label.setForeground(Color.BLACK);
label.setText(str);
SourceLineAnnotation link = bug.getPrimarySourceLineAnnotation();
if (link != null) {
label.addMouseListener(new BugSummaryMouseListener(bug, label, link));
}
return label;
}
public static Dialog getFunDialog() {
FileObject img = FileUtil.getConfigFile("BartGIfImage/BartSaturdayNightFever.gif");
FileObject audio = FileUtil.getConfigFile("BartAudio/STheme.wav");
final AudioClip clip = Applet.newAudioClip(audio.toURL());
Icon icon = new ImageIcon(img.toURL());
JLabel label = new JLabel(icon);
final Dialog dialog = new BartThemeDialog(WindowManager.getDefault().getMainWindow(), label);
label.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() == 1) {
clip.stop();
dialog.dispose();
}
}
});
clip.loop();
return dialog;
}
public StatusBar() {
Font font = new Font("Arial", Font.PLAIN, FontSize.getGuiFontSize());
setLayout(new BorderLayout(10, 0));
progressBar = new JProgressBar();
statusLabel = new JLabel();
statusLabel.setFont(font);
statusLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (ex != null) {
ErrorDialog.show(ex);
}
if (warnings != null) {
displayWarnings();
}
}
});
setStatus("Ready");
add(statusLabel, BorderLayout.WEST);
add(progressBar, BorderLayout.CENTER);
add(new JLabel(spacer), BorderLayout.EAST);
}
/**
* Add a path element
*
* @param path
* Path name
* @param newPath
*/
private void addPath(String path, final Object[] newPath) {
if (getComponentCount() > 0) {
Separator separator = new Separator();
separator.setPreferredSize(new Dimension(6, 25));
this.add(separator);
}
JLabel pathLabel = new JLabel(path);
pathLabel.setForeground(Color.WHITE);
this.add(pathLabel);
pathLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
listener.pathChanged(newPath);
}
});
}
private void initComponents()
{
setLayout(new BorderLayout());
componentLabel = new JLabel(getMember().toString());
componentLabel
.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
componentLabel.addMouseListener(new LinkMouseAdapter(this));
componentLabel.setToolTipText("Double-click to look-up in FIXwiki");
if (isRequired)
{
componentLabel.setForeground(Color.BLUE);
}
componentLabel.setFont(new Font(componentLabel.getFont().getName(),
Font.BOLD, componentLabel.getFont().getSize()));
membersPanel = new JPanel();
if (isRequired)
{
membersPanel.setBorder(new LineBorder(Color.BLUE));
} else
{
membersPanel.setBorder(new LineBorder(Color.BLACK));
}
loadMembers();
add(componentLabel, BorderLayout.NORTH);
add(membersPanel, BorderLayout.SOUTH);
}
private void setup() {
this.setLayout(new MigLayout("ins 0"));
skillLevelLabel = new JLabel("-");
skillLevelLabel.setFont(style.font);
skillLevelLabel.setForeground(style.foregroundColor);
this.setBackground(style.backgroundColor);
skillLevelLabel.addMouseListener(this);
skillImageLabel = new JLabel(
new ImageIcon(getClass().getClassLoader().getResource("resources/logo_" + skill + ".gif")));
skillImageLabel.addMouseListener(this);
add(skillImageLabel, "cell 0 0, ");
add(skillLevelLabel, "cell 1 0,");
}
/**
* Creates a new {@link IOObjectCacheEntryPanel}.
*
* @param icon
* The {@link Icon} associated with the entry's type.
* @param entryType
* Human readable representation of the entry's type (e.g., 'Data Table').
* @param openAction
* The action to be performed when clicking in the entry.
* @param removeAction
* An action triggering the removal of the entry.
*/
public IOObjectCacheEntryPanel(Icon icon, String entryType, Action openAction, Action removeAction) {
super(ENTRY_LAYOUT);
this.openAction = openAction;
// add icon label
JLabel iconLabel = new JLabel(icon);
add(iconLabel, ICON_CONSTRAINTS);
// add object type label
JLabel typeLabel = new JLabel(entryType);
typeLabel.setMaximumSize(new Dimension(MAX_TYPE_WIDTH, 24));
typeLabel.setPreferredSize(typeLabel.getMaximumSize());
typeLabel.setToolTipText(entryType);
add(typeLabel, TYPE_CONSTRAINTS);
// add link button performing the specified action, the label displays the entry's key name
LinkLocalButton openButton = new LinkLocalButton(openAction);
openButton.setMargin(new Insets(0, 0, 0, 0));
add(openButton, KEY_CONSTRAINTS);
// add removal button
JButton removeButton = new JButton(removeAction);
removeButton.setBorderPainted(false);
removeButton.setOpaque(false);
removeButton.setMinimumSize(buttonSize);
removeButton.setPreferredSize(buttonSize);
removeButton.setContentAreaFilled(false);
removeButton.setText(null);
add(removeButton, REMOVE_BUTTON_CONSTRAINTS);
// register mouse listeners
addMouseListener(hoverMouseListener);
iconLabel.addMouseListener(dispatchMouseListener);
typeLabel.addMouseListener(dispatchMouseListener);
openButton.addMouseListener(dispatchMouseListener);
removeButton.addMouseListener(dispatchMouseListener);
}
private JPanel createVersionPanel() {
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
panel.add(versionText);
Version specVersion = Version.parseVersion(engineModuleInfo.getSpecificationVersion().toString());
String versionString = String.format("%s.%s.%s", specVersion.getMajor(), specVersion.getMinor(), specVersion.getMicro());
String changelogUrl = releaseNotesUrlString + versionString;
final JLabel releaseNoteLabel = new JLabel("<html><a href=\"" + changelogUrl + "\">Release Notes</a>");
releaseNoteLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
releaseNoteLabel.addMouseListener(new BrowserUtils.URLClickAdaptor(changelogUrl));
panel.add(releaseNoteLabel);
return panel;
}
private JLabel getBackLabel(Consumer<AbstractCustomView> onBackClicked) {
JLabel backLabel = new JLabel("", getBackIcon(), JLabel.CENTER);
final AppPanel self = this;
backLabel.addMouseListener(
new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
AbstractCustomView customView = (AbstractCustomView) self.getRootPane().getParent();
onBackClicked.accept(customView);
}
});
backLabel.setVerticalAlignment(SwingConstants.CENTER);
return backLabel;
}
/**
* Creates and returns a link to open error details (the system messages).
* @return a link to open error details (the system messages)
*/
public static JLabel createErrorDetailsLink() {
final JLabel detailsLink = GeneralUtils.createLinkStyledLabel( Language.getText( "general.errorDetails" ) );
detailsLink.addMouseListener( new MouseAdapter() {
@Override
public void mousePressed( final MouseEvent event ) {
MainFrame.INSTANCE.viewSystemMessagesMenuItem.doClick();
};
} );
return detailsLink;
}
private JComponent createRestartNotificationDetails() {
JPanel res = new JPanel( new BorderLayout( 10, 10) );
res.setOpaque( false );
JLabel lbl = new JLabel( NbBundle.getMessage( LafPanel.class, "Descr_Restart") ); //NOI18N
lbl.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
res.add( lbl, BorderLayout.CENTER );
final JCheckBox checkEditorColors = new JCheckBox( NbBundle.getMessage( LafPanel.class, "Hint_ChangeEditorColors" ) ); //NOI18N
if( isChangeEditorColorsPossible() ) {
checkEditorColors.setSelected( true );
checkEditorColors.setOpaque( false );
res.add( checkEditorColors, BorderLayout.SOUTH );
}
lbl.addMouseListener( new MouseAdapter() {
@Override
public void mouseClicked( MouseEvent e ) {
if( null != restartNotification ) {
restartNotification.clear();
restartNotification = null;
}
if( checkEditorColors.isSelected() ) {
switchEditorColorsProfile();
}
LifecycleManager.getDefault().markForRestart();
LifecycleManager.getDefault().exit();
}
});
return res;
}
/** Creates a new instance of RecentProjects */
public Logo( String img, String url ) {
super( new BorderLayout() );
Icon image = new ImageIcon( ImageUtilities.loadImage(img, true) );
JLabel label = new JLabel( image );
label.setBorder( BorderFactory.createEmptyBorder() );
label.setOpaque( false );
label.addMouseListener( this );
setOpaque( false );
add( label, BorderLayout.CENTER );
setCursor( Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) );
this.url = url;
}
private
Panel
createDateQuickPicksPanel()
{
Panel panel = new Panel();
PopupMenu menu = new PopupMenu();
ActionHandler handler = new ActionHandler();
JLabel view = new JLabel(getProperty("periods"));
// Add items to menu.
menu.add(createMenuItem(ACTION_THIS_MONTH, handler));
menu.add(createMenuItem(ACTION_THIS_YEAR, handler));
menu.addSeparator();
menu.add(createMenuItem(ACTION_LAST_MONTH, handler));
menu.add(createMenuItem(ACTION_LAST_YEAR, handler));
menu.addSeparator();
menu.add(createMenuItem(ACTION_FORTNIGHT, handler));
menu.addSeparator();
menu.add(createMenuItem(ACTION_ALL, handler));
menu.setBehaveLikeMenu(true);
view.addMouseListener(menu);
view.setHorizontalTextPosition(SwingConstants.LEFT);
view.setIcon(MENU_ARROW.getIcon());
// Build panel.
panel.add(ACTIONS.getIcon(), 0, 0, 1, 1, 0, 100);
panel.add(view, 1, 0, 1, 1, 100, 0);
return panel;
}
private JLabel getOnlineLink(String key, String url) {
JLabel label = ulJLabel(Constant.messages.getString(key));
label.setIcon(ExtensionQuickStart.ONLINE_DOC_ICON);
label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
label.addMouseListener(
new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
DesktopUtils.openUrlInBrowser(url);
}
});
return label;
}
private void initSiteLink(JLabel label, MouseListener mouseListener) {
if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
return;
}
label.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
label.setForeground(Color.blue);
label.addMouseListener(mouseListener);
}
public FileCellEditor(JFileChooser fileChooser) {
this.fileChooser = fileChooser;
button = new JLabel();
button.addMouseListener(this);
}
/**
* Create a new tab with the given filename (if filename==null, we'll create a
* blank tab instead)
* <p>
* If a text buffer with that filename already exists, we will just switch to
* it; else we'll read that file into a new tab.
*
* @return false iff an error occurred
*/
public boolean newtab(String filename) {
if (filename != null) {
filename = Util.canon(filename);
for (int i = 0; i < tabs.size(); i++)
if (tabs.get(i).getFilename().equals(filename)) {
if (i != me)
select(i);
return true;
}
}
final JLabel lb = OurUtil.label("", OurUtil.getVizFont().deriveFont(Font.BOLD), Color.BLACK, Color.WHITE);
lb.setBorder(new OurBorder(BORDER, BORDER, Color.WHITE, BORDER));
lb.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
for (int i = 0; i < tabs.size(); i++)
if (tabs.get(i).obj1 == lb)
select(i);
}
});
JPanel h1 = OurUtil.makeH(4);
h1.setBorder(new OurBorder(null, null, BORDER, null));
JPanel h2 = OurUtil.makeH(3);
h2.setBorder(new OurBorder(null, null, BORDER, null));
JPanel pan = Util.onMac() ? OurUtil.makeVL(null, 2, OurUtil.makeHB(h1, lb, h2)) : OurUtil.makeVL(null, 2, OurUtil.makeHB(h1, lb, h2, GRAY), GRAY);
pan.setAlignmentX(0.0f);
pan.setAlignmentY(1.0f);
OurSyntaxWidget text = new OurSyntaxWidget(this, syntaxHighlighting, "", fontName, fontSize, tabSize, lb, pan);
tabBar.add(pan, tabs.size());
tabs.add(text);
text.listeners.add(listener); // add listener AFTER we've updated
// this.tabs and this.tabBar
if (filename == null) {
text.discard(false, getFilenames()); // forces the tab to re-derive
// a suitable fresh name
} else {
if (!text.load(filename))
return false;
for (int i = tabs.size() - 1; i >= 0; i--)
if (!tabs.get(i).isFile() && tabs.get(i).getText().length() == 0) {
tabs.get(i).discard(false, getFilenames());
close(i);
break; // Remove the rightmost untitled empty tab
}
}
select(tabs.size() - 1); // Must call this to switch to the new tab; and
// it will fire STATUS_CHANGE message which
// is important
return true;
}
/**
* Creates a new IconTextField with Icon.
*/
public TelephoneTextField() {
setLayout(new GridBagLayout());
setBackground(new Color(212, 223, 237));
pad = new PhonePad();
textField = new JTextField();
textField.setBorder(null);
setBorder(new JTextField().getBorder());
imageComponent = new JLabel(PhoneRes.getImageIcon("ICON_NUMBERPAD_IMAGE"));
add(imageComponent, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0));
add(textField, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 5), 0, 0));
imageComponent.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
displayPad(e);
}
});
textField.requestFocus();
textField.setForeground((Color)UIManager.get("TextField.lightforeground"));
textField.setText(textFieldText);
textField.addFocusListener(this);
textField.addMouseListener(this);
textField.addKeyListener(this);
}