JLabel label = new JLabel("Underlined Label"); Font font = label.getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); label.setFont(font.deriveFont(attributes));
import java.awt.*; public class TestComponent extends JPanel { private void drawString(Graphics g, String text, int x, int y) { for (String line : text.split("\n")) g.drawString(line, x, y += g.getFontMetrics().getHeight()); } public void paintComponent(Graphics g) { super.paintComponent(g); drawString(g, "hello\nworld", 20, 20); g.setFont(g.getFont().deriveFont(20f)); drawString(g, "part1\npart2", 120, 120); } public static void main(String s[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new TestComponent()); f.setSize(220, 220); f.setVisible(true); } }
public AboutDialog(JFrame parent) { this.setResizable(false); this.setSize(new Dimension(400, 250)); this.getContentPane().setLayout(new BorderLayout(0, 0)); JLabel lblResizer = new JLabel(Localization.get("app_name") + " " + Configuration.getVersion()); lblResizer.setBorder(new EmptyBorder(10, 10, 10, 10)); lblResizer.setVerticalTextPosition(SwingConstants.BOTTOM); lblResizer.setIconTextGap(10); lblResizer.setFont(lblResizer.getFont().deriveFont( lblResizer.getFont().getStyle() | Font.BOLD, 16f)); lblResizer.setIcon(new ImageIcon(AboutDialog.class .getResource("/img/icon_64.png"))); this.getContentPane().add(lblResizer, BorderLayout.NORTH); JTextArea txtrResizerIsA = new JTextArea(); txtrResizerIsA.setEditable(false); txtrResizerIsA.setWrapStyleWord(true); txtrResizerIsA.setBorder(new EmptyBorder(0, 10, 10, 10)); txtrResizerIsA.setFont(UIManager.getFont("Label.font")); txtrResizerIsA.setLineWrap(true); txtrResizerIsA.setText(Localization.get("about_text")); txtrResizerIsA.setBackground(new Color(0, 0, 0, 0)); this.getContentPane().add(txtrResizerIsA, BorderLayout.CENTER); this.setLocationRelativeTo(parent); }
super(txt); setForeground(Color.WHITE); setFont(getFont().deriveFont(Font.BOLD, 13)); setContentAreaFilled(false); setBorder(null); JLabel usrNameLabel = new JLabel("User Name"); changeCompFont(usrNameLabel); usrNameLabel.setLabelFor(usrNameFeild); JLabel passwordLabel = new JLabel("Password"); changeCompFont(passwordLabel); add(usrNameLabel, labCnst); add(usrNameFeild, txtCnst); add(passwordLabel, labCnst); add(passFeild, txtCnst); comp.setFont(getFont().deriveFont(Font.BOLD, 13)); JFrame frame = new JFrame("Demo: LogIn Dialogue"); frame.add(new MainContainer()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
JFrame frame = new JFrame(); frame.setUndecorated(true); frame.setBackground(new Color(0, 0, 0, 0.1f)); contentPane.setLayout(new OverlayLayout(contentPane)); JLabel label = new JLabel("TRANSPARENCY"); label.setOpaque(false); label.setAlignmentX(0.5f); label.setAlignmentY(0.5f); Font font = Story.myFont; label.setFont(font.deriveFont(Font.PLAIN, 72f)); label.setForeground(Color.WHITE); label.setBackground(Color.RED); label.setOpaque(true); contentPane.add(label);
cache.addChangeListener(model); frame=new JFrame("ReplCacheDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); table.setFont(table.getFont().deriveFont(Font.BOLD)); add(new JScrollPane(table)); key.add(new JLabel("Key ")); key.add(key_field); add(key); value.add(new JLabel("Value")); value.add(value_field); add(value); repl_count.add(new JLabel("Replication count")); repl_count.add(repl_count_field); add(repl_count);
JLabel labelConsoles = new JLabel(I18n.valueByKey("NETWORK_TAB_URL_LABEL")); NETWORK_TAB_DETAIL.setTabComponentAt( NETWORK_TAB_DETAIL.indexOfTab(I18n.valueByKey("NETWORK_TAB_URL_LABEL")), JLabel labelConsoleq = new JLabel(I18n.valueByKey("NETWORK_TAB_RESPONSE_LABEL")); NETWORK_TAB_DETAIL.setTabComponentAt( NETWORK_TAB_DETAIL.indexOfTab(I18n.valueByKey("NETWORK_TAB_RESPONSE_LABEL")), JLabel labelConsoleds = new JLabel(I18n.valueByKey("NETWORK_TAB_SOURCE_LABEL")); NETWORK_TAB_DETAIL.setTabComponentAt( NETWORK_TAB_DETAIL.indexOfTab(I18n.valueByKey("NETWORK_TAB_SOURCE_LABEL")), Component currentTabHeader = tabs.getTabComponentAt(tabs.getSelectedIndex()); if (currentTabHeader != null) { currentTabHeader.setFont(currentTabHeader.getFont().deriveFont(Font.PLAIN)); currentTabHeader.setForeground(Color.BLACK);
import java.awt.GridLayout; import javax.swing.*; import javax.swing.border.BevelBorder; public class FrameTest { public static void main(String[] args) { final JFrame f = new JFrame("Frame Test"); JPanel panel = new JPanel(new GridLayout(4, 4, 3, 3)); for (int i = 0; i < 16; i++) { JLabel l = new JLabel("" + i, JLabel.CENTER); //JLabel l = new JLabel(new ImageIcon("image_file.png"), JLabel.CENTER); l.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); l.setFont(l.getFont().deriveFont(20f)); panel.add(l); } f.setContentPane(panel); f.setSize(200, 200); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } }
JLabel label = new JLabel("Underlined Label"); Font font = label.getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); label.setFont(font.deriveFont(attributes));
gbc.gridx = 0; ripPanel.add(new JLabel("URL:", JLabel.RIGHT), gbc); gbc.weightx = 1; gbc.weighty = 1; gbc.weightx = 1; statusLabel = new JLabel(rb.getString("inactive")); statusLabel.setHorizontalAlignment(JLabel.CENTER); openButton = new JButton(); optionQueue = new JButton(rb.getString("Queue")); optionConfiguration = new JButton(rb.getString("Configuration")); optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); try { Image icon; configUpdateLabel = new JLabel( rb.getString("current.version") + ": " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT); configThreadsLabel = new JLabel(rb.getString("max.download.threads") + ":", JLabel.RIGHT); configTimeoutLabel = new JLabel(rb.getString("timeout.mill"), JLabel.RIGHT); gbc.gridy = 0; pane.add(ripPanel, gbc); gbc.gridy = 1; pane.add(statusPanel, gbc); gbc.gridy = 2; pane.add(progressPanel, gbc); gbc.gridy = 3; pane.add(optionsPanel, gbc); gbc.weighty = 1;
public static void main(String[] a) { GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); for (Font i : e.getAllFonts()) { String name = i.getFontName(); //if (name.startsWith("HelveticaNeue")) { JLabel label = new JLabel(name); label.setFont(i.deriveFont(18f)); contentPane.add(label); //} } JFrame frame = new JFrame("Fonts"); frame.setContentPane(ViewUtil.getClearBorderlessScrollPane(contentPane)); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }
configurationPanel.setVisible(false); if (logPanel.isVisible()) { optionLog.setFont(optionLog.getFont().deriveFont(Font.BOLD)); } else { optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); pack(); }); queuePanel.setVisible(false); configurationPanel.setVisible(false); optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); if (historyPanel.isVisible()) { optionHistory.setFont(optionLog.getFont().deriveFont(Font.BOLD)); } else { optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); pack(); }); emptyPanel.setVisible(!queuePanel.isVisible()); configurationPanel.setVisible(false); optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
Font f = getFont().deriveFont(Font.BOLD, 70); GlyphVector v = f.createGlyphVector(getFontMetrics(f).getFontRenderContext(), "Hello"); s = v.getOutline(); JFrame f = new JFrame("Test"); Component c = new Test(); f.getContentPane().add(c); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true);
private JComponent getNorthLabel() { final JLabel text = new JLabel("PlantUML (" + Version.versionString() + ")"); final Font font = text.getFont().deriveFont(Font.BOLD, (float) 20.0); text.setFont(font); final JPanel ptext = new JPanel(); ptext.add(text); final JLabel icon = new JLabel(new ImageIcon(PSystemVersion.getPlantumlImage())); final JPanel result = new JPanel(new BorderLayout()); result.add(ptext, BorderLayout.CENTER); result.add(icon, BorderLayout.EAST); return result; }
JLabel label = new JLabel(FocusableTip.getString("FocusHotkey")); Color fg = UIManager.getColor("Label.disabledForeground"); Font font = textArea.getFont(); font = font.deriveFont(font.getSize2D() - 1.0f); label.setFont(font); if (fg==null) { // Non BasicLookAndFeel-derived Looks sp.setBackground(textArea.getBackground()); sp.getViewport().setBackground(textArea.getBackground()); cp.add(sp); cp.add(panel, BorderLayout.SOUTH);
font = font.deriveFont(Font.PLAIN, 24f); JLabel label = new JLabel("?"); label.setFont(font); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridBagLayout()); frame.add(label); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } catch (IOException | FontFormatException exp) { exp.printStackTrace();
private JComponent getNorthLabel() { final JLabel text = new JLabel("PlantUML (" + Version.versionString() + ")"); final Font font = text.getFont().deriveFont(Font.BOLD, (float) 20.0); text.setFont(font); final JPanel ptext = new JPanel(); ptext.add(text); final JLabel icon = new JLabel(new ImageIcon(PSystemVersion.getPlantumlImage())); final JPanel result = new JPanel(new BorderLayout()); result.add(ptext, BorderLayout.CENTER); result.add(icon, BorderLayout.EAST); return result; }
JFrame frame = new JFrame("Title"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(pane); frame.pack(); frame.setVisible(true); pane.add(newLabel(labelText)); pane.add(newButton("Open dialog"), BorderLayout.SOUTH); return pane; dialog.setModal(true); dialog.add(newPane("Label in dialog")); dialog.pack(); dialog.setVisible(true); JLabel l = new JLabel(label); l.setFont(l.getFont().deriveFont(24.0f)); return l;
titlePanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); JLabel label = new JLabel(name); titlePanel.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 6, 3, 6), 0, 0)); label.setFont(label.getFont().deriveFont(Font.BOLD)); descriptionLabel = new JLabel(description); titlePanel.add(descriptionLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 6, 3, 6), 0, 0));
JFrame frame = new JFrame(TestOpenCloud.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); Cloud cloud = new Cloud(); final JLabel label = new JLabel(tag.getName()); label.setOpaque(false); label.setFont(label.getFont().deriveFont((float) tag.getWeight() * 10)); panel.add(label); frame.add(panel); frame.setSize(800, 600); frame.setVisible(true);