/** * Returns whether the Nimbus Look and Feel is installed. * * @return Whether the current LAF is Nimbus. */ private static boolean isNimbusLookAndFeel() { return UIManager.getLookAndFeel().getName().equals("Nimbus"); }
panelName.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, panelName.getForeground())); panelName.setFont(doDeriveFont(panelName.getFont(), Font.BOLD)); labelPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 11)); rightPanel.setBorder(BorderFactory.createEmptyBorder(0, 12, 11, 11)); panelName.setLabelFor(labelPanel); nbErrorForeground = UIManager.getColor("nb.errorForeground"); //NOI18N if (nbErrorForeground == null) { nbErrorForeground = new Color(255, 0, 0); // RGB suggested by jdinga in #65358 nbWarningForeground = UIManager.getColor("nb.warningForeground"); //NOI18N if (nbWarningForeground == null) { nbWarningForeground = new Color(51, 51, 51); // Label.foreground nbInfoForeground = UIManager.getColor("nb.warningForeground"); //NOI18N if (nbInfoForeground == null) { nbInfoForeground = UIManager.getColor("Label.foreground"); //NOI18N if ((getBorder() == null) || "GTK".equals(UIManager.getLookAndFeel().getID())) {
/** * Retourne une étiquette pour la composante spécifiée. Le texte de l'étiquette pourra * éventuellement être distribué sur plusieurs lignes. * * @param owner Composante pour laquelle on construit une étiquette. L'étiquette aura la même * largeur que {@code owner}. * @param text Texte à placer dans l'étiquette. */ public static JComponent getMultilineLabelFor(final JComponent owner, final String text) { final JTextArea label = new JTextArea(text); final Dimension size = owner.getPreferredSize(); size.height = label.getMaximumSize().height; label.setMaximumSize(size); label.setWrapStyleWord(true); label.setLineWrap(true); label.setEditable(false); label.setFocusable(false); label.setOpaque(false); label.setBorder(null); // Certains L&F placent une bordure. LookAndFeel.installColorsAndFont( label, "Label.background", "Label.foreground", "Label.font"); return label; }
button = new javax.swing.JButton(); button.setText("Text"); add(button); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); this.pack(); Color c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); try { LookAndFeel lnf = UIManager.getLookAndFeel().getClass().newInstance(); UIDefaults uiDefaults = lnf.getDefaults(); uiDefaults.put("nimbusBase", c); UIManager.getLookAndFeel().uninitialize(); UIManager.setLookAndFeel(lnf); } catch (InstantiationException ex) { } catch (IllegalAccessException ex) {
b.putClientProperty("JComponent.sizeVariant", size); return b; private static final Color BACKGROUND_COLOR = new Color(173, 193, 226); private static final Color SELECT_COLOR = new Color(102, 132, 186); if (b.isContentAreaFilled()) { g.setColor(SELECT_COLOR); g.fillRect(0, 0, b.getWidth(), b.getHeight()); protected void installDefaults(AbstractButton b) { super.installDefaults(b); b.setFont(b.getFont().deriveFont(11f)); UIManager.getInstalledLookAndFeels(); List<String> names = new ArrayList<String>(); for (UIManager.LookAndFeelInfo info : available) { String current = UIManager.getLookAndFeel().getName(); combo.setSelectedItem(current); combo.addActionListener(new ActionListener() { int index = combo.getSelectedIndex(); try { UIManager.setLookAndFeel( available[index].getClassName()); SwingUtilities.updateComponentTreeUI(parent);
font1 = Font.createFont(Font.TRUETYPE_FONT, SystemFontDisplayer.class.getResourceAsStream("/Images/SourceSansPro-Regular.ttf")); font2 = Font.createFont(Font.TRUETYPE_FONT, SystemFontDisplayer.class.getResourceAsStream("/Images/SourceSansPro-Regular.otf")); } catch (FontFormatException ex) { Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex); if (e.getStateChange() == ItemEvent.SELECTED) { final String fontName = fontsBox.getSelectedItem().toString(); fontsBox.setFont(new Font(fontName, Font.PLAIN, 16)); start(); LookAndFeel lnf = UIManager.getLookAndFeel().getClass().newInstance(); final FontUIResource res = new FontUIResource(fnt); UIDefaults uiDefaults = lnf.getDefaults(); uiDefaults.put("defaultFont", res); UIManager.getLookAndFeel().uninitialize(); UIManager.setLookAndFeel(lnf); } catch (InstantiationException ex) { Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex); final FontUIResource res = new FontUIResource(fnt); final Object fntObj = value; final String fontFamilyName = (String) fntObj; setFont(new Font(fontFamilyName, Font.PLAIN, 16)); return this;
if (UIManager.getLookAndFeel().getName().equals("Nimbus")) { Color selBG = textArea.getSelectionColor(); Color selFG = textArea.getSelectedTextColor(); textArea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); Font font = UIManager.getFont("Label.font"); if (font == null) { // Try to make a sensible default font = new Font("SansSerif", Font.PLAIN, 12); "body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt; }");
this.useLabels = UIManager.getLookAndFeel().getID().equals("Aqua"); final Border border = UIManager.getBorder("TableHeader.cellBorder"); this.normalLabel = new JLabel(); this.normalLabel.setHorizontalAlignment(SwingConstants.LEADING); this.ascendingLabel = new JLabel(); this.ascendingLabel.setHorizontalAlignment(SwingConstants.LEADING); this.ascendingLabel.setHorizontalTextPosition(SwingConstants.LEFT);
searchTextField.setFont(component.getFont()); searchPanel = new SearchPanel(component, isAlwaysShown()); final JLabel lbl; if (popupMenu != null) { lbl = new JLabel(org.openide.util.ImageUtilities.loadImageIcon(ICON_FIND_WITH_MENU, false)); lbl.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { lbl = new JLabel(org.openide.util.ImageUtilities.loadImageIcon(ICON_FIND, false)); if ("Aqua".equals(UIManager.getLookAndFeel().getID())) { //NOI18N if (popupMenu != null) { final JPopupMenu dummy = new JPopupMenu(); searchPanel.setBackground(component.getBackground()); lbl.setLabelFor(searchTextField); searchTextField.setColumns(10); searchTextField.setMaximumSize(searchTextField.getPreferredSize()); searchTextField.putClientProperty("JTextField.variant", "search"); //NOI18N lbl.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); if (constraints == null) { component.add(searchPanel); } else { component.add(searchPanel, constraints);
+ "text the same way as JTextArea does?"; private javax.swing.Timer timer = null; final Font fnt = new Font("Brodway", Font.BOLD, 10); textPane.setBorder(new JTextArea().getBorder()); textPane.setText(str); textArea.setText(str); LookAndFeel lnf = UIManager.getLookAndFeel().getClass().newInstance(); final FontUIResource res = new FontUIResource(fnt); UIDefaults uiDefaults = lnf.getDefaults(); UIManager.getLookAndFeel().uninitialize(); UIManager.setLookAndFeel(lnf); } catch (InstantiationException ex) { Logger.getLogger(SystemFontDisplayer.class.getName()).log(Level.SEVERE, null, ex); UIDefaults defaults = UIManager.getDefaults(); final FontUIResource res = new FontUIResource(fnt); final FontUIResource res = new FontUIResource(new Font("Algerian", Font.BOLD, 10)); for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) {
private Screen() { Font font = new JLabel().getFont(); float scaling = 1; int size = font.getSize(); int fontScalingPercent = Settings.getInstance().get(Keys.SETTINGS_FONT_SCALING); int s = fontScalingPercent * size / 100; if (s != size) { scaling = ((float) s) / size; size = s; font = font.deriveFont((float) s); for (Object key : javax.swing.UIManager.getLookAndFeel().getDefaults().keySet()) { if (key.toString().endsWith(".font")) javax.swing.UIManager.put(key, font); if (!IS_MAC) { // macOS has its own icon handling if (key.toString().endsWith(".icon") || key.toString().endsWith("Icon")) { Icon icon = UIManager.getIcon(key); if (icon != null) javax.swing.UIManager.put(key, new ScaleIcon(icon, scaling)); } } } UIManager.put("ScrollBar.width", size * 17 / 12); } this.scaling = scaling; this.size = size; this.font = font; }
UIManager.getSystemLookAndFeelClassName(), UIManager.getCrossPlatformLookAndFeelClassName() }; for (String name : names) { try { UIManager.setLookAndFeel(name); } catch (Exception e) { e.printStackTrace(); JFrame f = new JFrame(UIManager.getLookAndFeel().getName()); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); gui.add(tree, BorderLayout.LINE_START); gui.add(new JScrollPane(new JTextArea(3,15))); gui.add(toolbar, BorderLayout.PAGE_START); for (int ii=1; ii<5; ii++) { toolbar.add(new JButton("Button " + ii));
/** * Returns the default background color to use for tool tip windows. * * @return The default background color. */ public static Color getToolTipBackground() { Color c = UIManager.getColor("ToolTip.background"); // Tooltip.background is wrong color on Nimbus (!) if (c == null || UIManager.getLookAndFeel().getName().equals("Nimbus")) { c = UIManager.getColor("info"); // Used by Nimbus (and others) if (c == null) { c = SystemColor.info; // System default } } // Workaround for a bug (?) with Nimbus - calling JLabel.setBackground() // with a ColorUIResource does nothing, must be a normal Color if (c instanceof ColorUIResource) { c = new Color(c.getRGB()); } return c; }
/** * Initializes the button. */ protected void initialize() { if (!System.getProperty("java.version").startsWith("1.3")) { setOpaque(false); setBackground(new java.awt.Color(0, 0, 0, 0)); } setBorderPainted(false); setMargin(new Insets(2, 2, 2, 2)); // Windows XP look and feel seems to have a bug due to which the // size of the parent container changes when the border painted // property is set. Temporary fix: disable mouseover behavior if // installed lnf is Windows XP if (!UIManager.getLookAndFeel().getName().equals("Windows")) { addMouseListener(new MouseListener()); } }
private Color getDefaultBackground() { Color color = null; String[] keys = new String[]{"Button.background", "Label.background", "Panel.background"}; for (String key : keys) { color = UIManager.getLookAndFeel().getDefaults().getColor(key); } if (color == null) { color = new Color(238, 238, 238); } return color; } }
public static GradientPanel createGradientPanel() { final GradientPanel gp = new GradientPanel(); final LookAndFeel laf = UIManager.getLookAndFeel(); final boolean isAqua = laf == null ? false : laf.getID().equals( "Aqua" ); final GradientPaint grad = isAqua ? new GradientPaint( 0f, 0f, new Color( 0xF3, 0xF3, 0xF3 ), 0f, 69f, new Color( 0xC4, 0xC4, 0xC4 )) : null; gp.setLayout( new BoxLayout( gp, BoxLayout.X_AXIS )); gp.setGradient( grad ); gp.setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 )); return gp; }
lfPanel.setBorder(BorderFactory.createTitledBorder(Translator.get("prefs_dialog.look_and_feel"))); tempPanel.add(new JLabel(Translator.get("setup.look_and_feel") + ':')); lfPanel.add(tempPanel); lfInfo = UIManager.getInstalledLookAndFeels(); currentLf = UIManager.getLookAndFeel().getName(); selectedIndex = -1;
private void setDefaults() { this.setEditable(false); this.setCursor(null); this.setBorder(null); this.setBackground(new Color(UIManager.getLookAndFeel().getDefaults().getColor("Label.background").getRGB())); this.setForeground(new Color(UIManager.getLookAndFeel().getDefaults().getColor("Label.foreground").getRGB())); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { Font font = textArea.getFont(); float oldSize = font.getSize2D(); float newSize = oldSize - decreaseAmount; if (newSize>=MINIMUM_SIZE) { // Shrink by decreaseAmount. font = font.deriveFont(newSize); textArea.setFont(font); } else if (oldSize>MINIMUM_SIZE) { // Can't shrink by full decreaseAmount, but can shrink a // little bit. font = font.deriveFont(MINIMUM_SIZE); textArea.setFont(font); } else { // Our font size must be at or below MINIMUM_SIZE. UIManager.getLookAndFeel().provideErrorFeedback(textArea); } textArea.requestFocusInWindow(); }
@Override protected void installDefaults() { LookAndFeel.installColorsAndFont(comboBox, "ComboBox.background", "ComboBox.foreground", "ComboBox.font"); //NOI18N if (tableUI) { comboBox.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0)); } else { comboBox.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(PropUtils.getShadowColor()), //leave room for the focus rect on the left, so it doesn't //overpaint the first pixel column of text BorderFactory.createEmptyBorder(0, 2, 0, 0) ) ); } installComboDefaults(comboBox); }