
net.java.balloontip.examples.complete.CompleteExample Maven / Gradle / Ivy
/**
* Balloontip - Balloon tips for Java Swing applications
* Copyright 2007-2010 Bernhard Pauler, Tim Molderez
*
* This file is part of Balloontip.
*
* Balloontip is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Balloontip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Balloontip. If not, see .
*/
package net.java.balloontip.examples.complete;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import net.java.balloontip.BalloonTip;
import net.java.balloontip.examples.complete.panels.MainPanel;
import net.java.balloontip.styles.BalloonTipStyle;
import net.java.balloontip.styles.MinimalBalloonStyle;
import net.java.balloontip.utils.TimingUtils;
import net.java.balloontip.utils.ToolTipUtils;
/**
* Main class for the Balloontip example application
* @author Tim Molderez
*/
public class CompleteExample {
private static BalloonTip errBalloon = null;
/**
* Main method
* @param args command-line arguments (unused)
*/
public static void main(String[] args) {
// First try to switch from the "Metal" L&F to the OS default
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {}
// Now create the GUI
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("BalloonTip example");
frame.setIconImage(new ImageIcon(CompleteExample.class.getResource("/net/java/balloontip/images/frameIcon.png")).getImage());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new MainPanel());
frame.pack();
frame.setSize(480, 640);
frame.setLocationRelativeTo(null); // Centers the frame on the screen
frame.setVisible(true);
}
});
}
/**
* Set a tooltip
* @param comp sets a tooltip for this component
* @param text the contents of the tooltip (you may use html)
*/
public static void setToolTip(final JComponent comp, final String text) {
BalloonTipStyle style = new MinimalBalloonStyle(new Color(169, 205, 221, 220), 5);
final BalloonTip balloon = new BalloonTip(comp, new JLabel(text), style, BalloonTip.Orientation.LEFT_ABOVE, BalloonTip.AttachLocation.ALIGNED, 15, 10, false);
balloon.addDefaultMouseListener(false);
ToolTipUtils.balloonToToolTip(balloon, 500, 3000);
}
/**
* Display an error balloon tip
* @param comp attach the balloon tip to this component
* @param text error message
*/
public static void showErrorMessage(JComponent comp, String text) {
if (errBalloon!=null) {
errBalloon.closeBalloon();
}
BalloonTipStyle style = new MinimalBalloonStyle(new Color(246, 197, 192, 220), 5);
errBalloon = new BalloonTip(comp, new JLabel("" + text + ""),
style, BalloonTip.Orientation.LEFT_ABOVE, BalloonTip.AttachLocation.ALIGNED, 15, 10, false);
errBalloon.addDefaultMouseListener(false);
TimingUtils.showTimedBalloon(errBalloon, 3000);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy