List of usage examples for javax.swing JLabel getFont
@Transient
public Font getFont()
From source file:Main.java
/** * Apply bold font to a Jlabel./*from www.j a v a2 s . c om*/ * @param label */ public static void bold(final JLabel label) { final Font font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() ^ Font.BOLD)); }
From source file:Main.java
/** * "Fixates" the preferred width of the given label to the given text. * // www .j a va 2 s . c o m * @param aLabel * the label to fixate, cannot be <code>null</code>; * @param aMinimalText * the text to use as minimal width indicator. */ public static final void fixLabelWidth(final JLabel aLabel, final String aMinimalText) { final FontMetrics fm = aLabel.getFontMetrics(aLabel.getFont()); final int height = fm.getHeight(); aLabel.setPreferredSize(new Dimension(fm.stringWidth(aMinimalText), height)); }
From source file:Main.java
/** * Displays a message dialog with given information. *//* w ww . jav a 2s . c om*/ public static void showInformationDialog(Component component, String message) { final JPanel panel = new JPanel(new BorderLayout(5, 5)); final JLabel messageLabel = new JLabel(message); messageLabel.setFont(new Font("Dialog", Font.BOLD, messageLabel.getFont().getSize())); panel.add(messageLabel, BorderLayout.CENTER); // Adjust stack trace dimensions final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); screenDimension.setSize(screenDimension.getWidth() * 0.7, screenDimension.getHeight() * 0.7); final Dimension maxStackTraceDimension = new Dimension(500, 500); maxStackTraceDimension.setSize(Math.min(maxStackTraceDimension.getWidth(), screenDimension.getWidth()), Math.min(maxStackTraceDimension.getHeight(), screenDimension.getHeight())); JOptionPane.showMessageDialog(component, panel, "Information", JOptionPane.INFORMATION_MESSAGE); }
From source file:QandE.MyDemo1.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./* ww w .j av a 2 s. com*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }
From source file:QandE.MyDemo3.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//from ww w. j av a 2 s. c o m */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo3"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); JButton b = new JButton("A button"); frame.getContentPane().add(BorderLayout.PAGE_END, b); frame.getRootPane().setDefaultButton(b); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }
From source file:QandE.MyDemo2.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from w w w. ja v a 2s .co m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("MyDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenu menu = new JMenu("Menu"); JMenuBar mb = new JMenuBar(); mb.add(menu); frame.setJMenuBar(mb); //Add a label with bold italic font. JLabel label = new JLabel("My Demo"); frame.getContentPane().add(BorderLayout.CENTER, label); if (true) { label.setFont(label.getFont().deriveFont(Font.ITALIC | Font.BOLD)); } else { //another way of doing it, but not as appropriate since //setFont is faster than using HTML. label.setText("<html><i>My Demo</i></html>"); } label.setHorizontalAlignment(JLabel.CENTER); //Display the window, making it a little bigger than it really needs to be. frame.pack(); frame.setSize(frame.getWidth() + 100, frame.getHeight() + 50); frame.setVisible(true); }
From source file:org.jdal.swing.form.FormUtils.java
/** * Make font of JLabel bold//w ww . j a v a 2 s .c o m * @param label JLabel to make bold */ public static void setBold(JLabel label) { label.setFont(label.getFont().deriveFont(Font.BOLD)); }
From source file:net.sf.texprinter.utils.UIUtils.java
/** * Formats a label as a title. The idea behind this method is to make * a JLabel component to look fancy when acting as a title to a window. * // w ww . j a va 2 s .co m * @param label The label to be formatted as a title. */ public static void formatLabelAsTitle(JLabel label) { // if it's not Linux if (!SystemUtils.IS_OS_LINUX) { // simply increase the font size label.setFont(label.getFont().deriveFont(14f)); } else { // it's Linux, so add a bold style too. label.setFont(label.getFont().deriveFont(Font.BOLD, 14f)); } // paint it as blue label.setForeground(new Color(35, 107, 178)); }
From source file:org.jdal.swing.form.FormUtils.java
/** * @param message/* w w w. j a va 2 s .c o m*/ * @return JLabel */ public static JLabel newLabelForBox(String message) { JLabel label = new JLabel(message); label.setMaximumSize(new Dimension(Short.MAX_VALUE, label.getFont().getSize() + 10)); label.setAlignmentX(Container.CENTER_ALIGNMENT); return label; }
From source file:com.clank.launcher.swing.SwingHelper.java
/** * Show a message dialog using//from w w w .j av a 2s . c om * {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)}. * * <p>The dialog will be shown from the Event Dispatch Thread, regardless of the * thread it is called from. In either case, the method will block until the * user has closed the dialog (or dialog creation fails for whatever reason).</p> * * @param parentComponent the frame from which the dialog is displayed, otherwise * null to use the default frame * @param message the message to display * @param title the title string for the dialog * @param messageType see {@link javax.swing.JOptionPane#showMessageDialog(java.awt.Component, Object, String, int)} * for available message types */ public static void showMessageDialog(final Component parentComponent, @NonNull final String message, @NonNull final String title, final String detailsText, final int messageType) { if (SwingUtilities.isEventDispatchThread()) { // To force the label to wrap, convert the message to broken HTML String htmlMessage = "<html><div style=\"width: 250px\">" + htmlEscape(message); JPanel panel = new JPanel(new BorderLayout(0, detailsText != null ? 20 : 0)); // Add the main message panel.add(new JLabel(htmlMessage), BorderLayout.NORTH); // Add the extra details if (detailsText != null) { JTextArea textArea = new JTextArea(_("errors.reportErrorPreface") + detailsText); JLabel tempLabel = new JLabel(); textArea.setFont(tempLabel.getFont()); textArea.setBackground(tempLabel.getBackground()); textArea.setTabSize(2); textArea.setEditable(false); textArea.setComponentPopupMenu(TextFieldPopupMenu.INSTANCE); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new Dimension(350, 120)); panel.add(scrollPane, BorderLayout.CENTER); } JOptionPane.showMessageDialog(parentComponent, panel, title, messageType); } else { // Call method again from the Event Dispatch Thread try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { showMessageDialog(parentComponent, message, title, detailsText, messageType); } }); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } }