/** Creates a new instance of TabsComponent */ public TabsComponent(boolean toolVis) { super(); bar = new JToolBar(); Border b = (Border)UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N bar.setBorder(b); bar.setFloatable(false); bar.setFocusable(true); if( "Windows".equals( UIManager.getLookAndFeel().getID()) && !isXPTheme()) { bar.setRollover(true); } else if( AQUA ) { bar.setBackground(UIManager.getColor("NbExplorerView.background")); } setLayout(new BorderLayout()); add(bar, BorderLayout.NORTH); startToggling(); setToolbarBarVisible(toolVis); }
public static void repaintBorder(final JComponent c) { JComponent borderedComponent = c; Border border = c.getBorder(); if (border == null) { // See if it's inside a JScrollpane or something final Container p = c.getParent(); if (p instanceof JViewport) { borderedComponent = (JComponent)p.getParent(); if (borderedComponent != null) border = borderedComponent.getBorder(); } } // If we really don't have a border, then bail // It might be a compound border with a ThemeBorder inside // The check for that case is tricky, so we just go ahead and repaint any border if (border == null || borderedComponent == null) return; final int width = borderedComponent.getWidth(); final int height = borderedComponent.getHeight(); final Insets i = borderedComponent.getInsets(); borderedComponent.repaint(0, 0, width, i.top); // Top edge borderedComponent.repaint(0, 0, i.left, height); // Left edge borderedComponent.repaint(0, height - i.bottom, width, i.bottom); // Bottom edge borderedComponent.repaint(width - i.right, 0, i.right, height); // Right edge }
/** * Creates and returns a Container containing the buttons. The buttons * are created by calling <code>getButtons</code>. */ protected Container createButtonArea() { JPanel bottom = new JPanel(); Border border = (Border)DefaultLookup.get(optionPane, this, "OptionPane.buttonAreaBorder"); bottom.setName("OptionPane.buttonArea"); if (border != null) { bottom.setBorder(border); } bottom.setLayout(new ButtonAreaLayout( DefaultLookup.getBoolean(optionPane, this, "OptionPane.sameSizeButtons", true), DefaultLookup.getInt(optionPane, this, "OptionPane.buttonPadding", 6), DefaultLookup.getInt(optionPane, this, "OptionPane.buttonOrientation", SwingConstants.CENTER), DefaultLookup.getBoolean(optionPane, this, "OptionPane.isYesLast", false))); addButtonComponents(bottom, getButtons(), getInitialValueIndex()); return bottom; }
private static void test(Border border) { Insets actual = border.getBorderInsets(null); if (NEGATIVE.equals(actual)) { throw new Error("unexpected insets in " + border.getClass()); } Insets expected = (Insets) actual.clone(); // modify actual.top++; actual.left++; actual.right++; actual.bottom++; // validate if (!expected.equals(border.getBorderInsets(null))) { throw new Error("shared insets in " + border.getClass()); } }
@Override public void paint(Graphics g) { if (!(component instanceof TranslatedTableCellRenderer)) { g.translate(-outline.getTreePositionX(), 0); } try { component.paint(g); } catch (NullPointerException npe) { // http://netbeans.org/bugzilla/show_bug.cgi?id=194055 javax.swing.border.Border border = null; Exceptions.printStackTrace(Exceptions.attachMessage(npe, "Failed painting of component "+component+ " with border "+((component instanceof JComponent) ? (border = ((JComponent) component).getBorder()) : null)+ ((border instanceof javax.swing.border.CompoundBorder) ? ", with outsideBorder = "+((javax.swing.border.CompoundBorder) border).getOutsideBorder()+ " and insideBorder = "+((javax.swing.border.CompoundBorder) border).getInsideBorder() : "") )); } }
/** * Uninstalls any state that this style installed on * the <code>JComponent</code> from <code>context</code>. * <p> * Styles should NOT depend upon this being called, in certain cases * it may never be called. * * @param context SynthContext identifying component to install properties * to. */ public void uninstallDefaults(SynthContext context) { if (!context.isSubregion()) { // NOTE: because getForeground, getBackground and getFont will look // at the parent Container, if we set them to null it may // mean we they return a non-null and non-UIResource value // preventing install from correctly settings its colors/font. For // this reason we do not uninstall the fg/bg/font. JComponent c = context.getComponent(); Border border = c.getBorder(); if (border instanceof UIResource) { c.setBorder(null); } } }
public FooterBar() { setPreferredSize(new Dimension(640, 16)); setLayout(new GridLayout()); setBorder(new BevelBorder(BevelBorder.LOWERED)); Border margin = new EmptyBorder(0, 5, 0, 5); label = new JLabel("Ready", SwingConstants.LEFT); label.setBorder(margin); add(label); progress = new JProgressBar(); progress.setMaximum(6); progress.setStringPainted(true); progress.setPreferredSize(new Dimension(10, 16)); progress.setValue(0); add(progress); }
public void configure( Color foreground, Color background, boolean isSelected, boolean hasFocus, int rowHeight, int rowWidth ) { removeAll(); int maxWidth = rowWidth - SelectionList.INSETS_LEFT - SelectionList.INSETS_RIGHT; JComponent inner = node.getComponent( foreground, background, isSelected, hasFocus, maxWidth > 0 ? maxWidth : 0); add( inner, BorderLayout.CENTER ); setBackground( background ); setForeground( foreground ); Border border = null; if( hasFocus ) { if( isSelected ) { border = UIManager.getBorder( "List.focusSelectedCellHighlightBorder" ); // NOI18N } if( border == null ) { border = UIManager.getBorder( "List.focusCellHighlightBorder" ); // NOI18N } } if( null != border ) { border = BorderFactory.createCompoundBorder( border, BorderFactory.createEmptyBorder( SelectionList.INSETS_TOP, SelectionList.INSETS_LEFT, SelectionList.INSETS_BOTTOM, SelectionList.INSETS_RIGHT ) ); } else { border = BorderFactory.createEmptyBorder( SelectionList.INSETS_TOP, SelectionList.INSETS_LEFT, SelectionList.INSETS_BOTTOM, SelectionList.INSETS_RIGHT ); } try { setBorder( border ); } catch( NullPointerException npe ) { //workaround for 175940 Logger.getLogger( ListRendererPanel.class.getName() ).log( Level.INFO, "Bug #175940", npe ); } RendererPanel.configureAccessibility(this, false); }
/** Assign the given attributes to the given JComponent, then return the JComponent again. * <p> If <b>Font</b> x is given in the list, we call obj.setFont(x) * <p> If <b>String</b> x is given in the list, we call obj.setToolTipText(x) * <p> If <b>Border</b> x is given in the list, we call obj.setBorder(x) * <p> If <b>Dimension</b> x is given in the list, we call obj.setPreferredSize(x) * <p> If <b>Color</b> x is given in the list, and it's the first color, we call obj.setForeground(x) * <p> If <b>Color</b> x is given in the list, and it's not the first color, we call obj.setBackground(x) then obj.setOpaque(true) * <p> (If no Font is given, then after all these changes have been applied, we will call obj.setFont() will a default font) */ public static<X extends JComponent> X make(X obj, Object... attributes) { boolean hasFont = false, hasForeground = false; if (attributes!=null) for(Object x: attributes) { if (x instanceof Font) { obj.setFont((Font)x); hasFont=true; } if (x instanceof String) { obj.setToolTipText((String)x); } if (x instanceof Border) { obj.setBorder((Border)x); } if (x instanceof Dimension) { obj.setPreferredSize((Dimension)x); } if (x instanceof Color && !hasForeground) { obj.setForeground((Color)x); hasForeground=true; continue; } if (x instanceof Color) { obj.setBackground((Color)x); obj.setOpaque(true); } } if (!hasFont) obj.setFont(getVizFont()); return obj; }
public void testGetter () { Scene scene = new Scene (); BevelBorder originalBorder = new BevelBorder (BevelBorder.RAISED); scene.setBorder (originalBorder); Border foundBorder = BorderSupport.getSwingBorder (scene.getBorder ()); assertEquals (originalBorder, foundBorder); }
public static void main(String[] args) { for (Border border : BORDERS) { System.out.println(border.getClass()); test(border, border.getBorderInsets(getComponent(border))); if (border instanceof AbstractBorder) { test((AbstractBorder) border); } } }
/** * If a border has been set on this component, returns the * border's insets, else calls super.getInsets. * * @return the value of the insets property. * @see #setBorder */ public Insets getInsets() { Border border = getBorder(); if (border != null) { return border.getBorderInsets(this); } return super.getInsets(); }
protected void installDefaults(final AbstractButton b) { // load shared instance defaults final String pp = getPropertyPrefix(); if (!defaults_initialized) { defaultDisabledTextColor = UIManager.getColor(pp + "disabledText"); defaults_initialized = true; } setButtonMarginIfNeeded(b, UIManager.getInsets(pp + "margin")); LookAndFeel.installColorsAndFont(b, pp + "background", pp + "foreground", pp + "font"); LookAndFeel.installProperty(b, "opaque", UIManager.getBoolean(pp + "opaque")); final Object borderProp = b.getClientProperty(BUTTON_TYPE); boolean hasBorder = false; if (borderProp != null) { hasBorder = setButtonType(b, borderProp); } if (!hasBorder) setThemeBorder(b); final Object segmentProp = b.getClientProperty(SEGMENTED_BUTTON_POSITION); if (segmentProp != null) { final Border border = b.getBorder(); if (!(border instanceof AquaBorder)) return; b.setBorder(AquaButtonExtendedTypes.getBorderForPosition(b, b.getClientProperty(BUTTON_TYPE), segmentProp)); } }
private static JComponent getComponent(Border border) { Class type = border.getClass(); if (type.equals(MotifBorders.MotifPopupMenuBorder.class)) { return POPUP; } if (type.equals(WindowsBorders.ToolBarBorder.class)) { return TOOLBAR; } if (type.equals(MetalBorders.ToolBarBorder.class)) { return TOOLBAR; } return LABEL; }
public void setProfilingPointFactory(ProfilingPointFactory ppFactory, int index) { this.ppFactory = ppFactory; if (ppFactory != null) { label.setText(ppFactory.getType()); label.setIcon(ppFactory.getIcon()); } else { label.setText(NO_ACTION_NAME); label.setIcon(NO_ACTION_ICON); } Component selected = null; if ((index >= 0) && (index < previewPanel.getComponentCount())) { selected = previewPanel.getComponent(index); } for (Component c : previewPanel.getComponents()) { if (c == selected) { Border empt1 = BorderFactory.createEmptyBorder(2, 2, 2, 2); Border sel = BorderFactory.createMatteBorder(1, 1, 1, 1, SystemColor.textHighlight); Border empt2 = BorderFactory.createEmptyBorder(0, 2, 0, 2); Border comp1 = BorderFactory.createCompoundBorder(empt2, sel); Border comp2 = BorderFactory.createCompoundBorder(comp1, empt1); ((JComponent) c).setBorder(comp2); } else { ((JComponent) c).setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5)); } } }
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { if (isSelected) { super.setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { super.setForeground(table.getForeground()); super.setBackground(table.getBackground()); } setFont(table.getFont()); if (hasFocus) { Border border = null; if (isSelected) { border = UIManager .getBorder("Table.focusSelectedCellHighlightBorder"); } if (border == null) { border = UIManager .getBorder("Table.focusCellHighlightBorder"); } setBorder(border); } else { setBorder(noFocusBorder); } return this; }
/** * The border gap is used in calculating the left and right insets of the * border. Default value is 5. * * @param borderGap the gap in pixels */ public void setBorderGap(int borderGap) { this.borderGap = borderGap; Border inner = new EmptyBorder(0, borderGap, 0, borderGap); setBorder( new CompoundBorder(OUTER, inner) ); lastDigits = 0; setPreferredWidth(); }
/** * Adds a given border to a given component. * If the component already has some border, the given border is put * around the existing border. * * @param component component the border should be added to * @param border the border to be added */ private static void addBorder(JComponent component, Border newBorder) { Border currentBorder = component.getBorder(); if (currentBorder == null) { component.setBorder(newBorder); } else { component.setBorder(BorderFactory.createCompoundBorder( newBorder, //outside currentBorder)); //inside } }
public static void main(String[] args) { Component c = new Component() {}; c.setBackground(Color.WHITE); c.setForeground(Color.BLACK); Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics(); g.setClip(0, 0, 1024, 768); for (Border border : BORDERS) { System.out.println(border.getClass()); border.getBorderInsets(c); border.paintBorder(c, g, 0, 0, 1024, 768); } }
protected Border createNonRolloverBorder() { if (XPStyle.getXP() != null) { return new EmptyBorder(3, 3, 3, 3); } else { return super.createNonRolloverBorder(); } }
public void testUseTitle() throws Exception { sleep(); sleep(); tagsRen2.setUseLabels(true); sleep(); Component c = tagsRen2.getRenderer(tagsRen2); if (!(c instanceof InplaceEditor)) { fail("Did not get an inplace editor for a renderer"); } InplaceEditor ine = (InplaceEditor) c; InplaceEditor innermost = PropUtils.findInnermostInplaceEditor(ine); if (!(innermost instanceof RadioInplaceEditor)) { fail("Should have gotten an instance of RadioInplaceEditor, not " + innermost); } Border b = innermost.getComponent().getBorder(); assertNotNull("Border should not be null when set to use labels", b); assertTrue("Border should be an instance of TitledBorder, not " + b, b instanceof TitledBorder); boolRen.setUseLabels(true); c = boolRen.getRenderer(boolRen); if (!(c instanceof InplaceEditor)) { fail("Did not get an inplace editor for a renderer"); } ine = (InplaceEditor) c; innermost = PropUtils.findInnermostInplaceEditor(ine); if (!(innermost instanceof CheckboxInplaceEditor)) { fail("Should have gotten an instance of RadioInplaceEditor, not " + innermost); } CheckboxInplaceEditor cb = (CheckboxInplaceEditor) innermost; assertEquals("If using labels, checkbox text should be the property display name", cb.getText(), boolRen.getProperty().getDisplayName()); }
/** * Maps {@code JComponent.setBorder(Border)} through queue */ public void setBorder(final Border border) { runMapping(new MapVoidAction("setBorder") { @Override public void map() { ((JComponent) getSource()).setBorder(border); } }); }
private void init() { Border b = UIManager.getBorder( "nb.popupswitcher.border" ); //NOI18N if( null == b ) b = BorderFactory.createLineBorder(getForeground()); setBorder(b); setShowHorizontalLines(false); // Calc row height here so that TableModel can adjust number of columns. calcRowHeight(getOffscreenGraphics()); }
@Override public void paint(Graphics g, JComponent c) { Border vpBorder = scrollpane.getViewportBorder(); if (vpBorder != null) { Rectangle r = scrollpane.getViewportBorderBounds(); vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height); } }
protected void setThemeBorder(final AbstractButton b) { super.setThemeBorder(b); Border border = b.getBorder(); if (border == null || border instanceof UIResource) { // Set the correct border b.setBorder(AquaButtonBorder.getBevelButtonBorder()); } }
private void initMinDimension(String... maxStrings) { FontMetrics fm = getFontMetrics(getFont()); int minWidth = 0; for (String s : maxStrings) { minWidth = Math.max(minWidth, fm.stringWidth(s)); } Border b = getBorder(); Insets ins = (b != null) ? b.getBorderInsets(this) : NULL_INSETS; minWidth += ins.left + ins.right; int minHeight = fm.getHeight() + ins.top + ins.bottom; minDimension = new Dimension(minWidth, minHeight); }
TemplatesTreeView() { tree.setEditable(false); //#219709 - workaround for JDK bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8003400 tree.setLargeModel( false ); // install proper border setBorder((Border)UIManager.get("Nb.ScrollPane.border")); // NOI18N }
/** * Created by Kevin Le to stylize buttons to all look the same * @param b */ public void stylizeButton(JButton b){ Border thickBorder = new LineBorder(Color.WHITE, 3); b.setBorder(thickBorder); b.setContentAreaFilled(false); b.setOpaque(true); b.setBackground(Color.BLACK); b.setForeground(Color.WHITE); }
public void drawTrack(){ int trackRectWidth = 12; int trackRectHeight = panelTrackView.getHeight(); Border thickBorder = new LineBorder(Color.WHITE, 2); JPanel trackRect = new JPanel(); trackRect.setOpaque(false); trackRect.setBorder(thickBorder); trackRect.setBounds(50, -4, trackRectWidth, trackRectHeight + 4); panelTrackView.add(trackRect); }
private void prepareRendererTable(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setName("Table.cellRenderer"); if(isSelected) { super.setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { Color background = table.getBackground(); if(background == null || background instanceof javax.swing.plaf.UIResource) { // Color alternateColor = DefaultLookup.getColor(this, ui, // "Table.alternateRowColor"); Color alternateColor = UIManager.getColor("Table.alternateRowColor"); if(alternateColor != null && row % 2 == 0) background = alternateColor; } super.setForeground(table.getForeground()); super.setBackground(background); } if(hasFocus) { Border border = null; if(isSelected) { border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); } if(border == null) { border = UIManager.getBorder("Table.focusCellHighlightBorder"); } setBorder(border); } else { setBorder(UIManager.getBorder("Table.cellNoFocusBorder")); } prepareRendererCommon(table, value, isSelected, hasFocus); }
/** * {@inheritDoc} * @since 1.6 */ protected Border getRolloverBorder(AbstractButton b) { XPStyle xp = XPStyle.getXP(); if (xp != null) { return xp.getBorder(b, WindowsButtonUI.getXPButtonType(b)); } else { return super.getRolloverBorder(b); } }
private void adjustToolbarPanelBorder() { if( toolbarPanel.getComponentCount() > 0 ) { Border b = UIManager.getBorder( "Nb.MainWindow.Toolbar.Border"); if( null != b ) { toolbarPanel.setBorder( b ); return; } //add border if ("Windows".equals(UIManager.getLookAndFeel().getID())) { //NOI18N if( isXPTheme() ) { if( isWindows8() ) { toolbarPanel.setBorder( BorderFactory.createEmptyBorder() ); } else { //Set up custom borders for XP toolbarPanel.setBorder(BorderFactory.createCompoundBorder( upperBorder, BorderFactory.createCompoundBorder( BorderFactory.createMatteBorder(0, 0, 1, 0, fetchColor("controlShadow", Color.DARK_GRAY)), BorderFactory.createMatteBorder(0, 0, 1, 0, mid)) )); //NOI18N } } else { toolbarPanel.setBorder( BorderFactory.createEtchedBorder() ); } } else if ("GTK".equals(UIManager.getLookAndFeel().getID())) { //NOI18N //No border toolbarPanel.setBorder(BorderFactory.createEmptyBorder()); } } else { if ("GTK".equals(UIManager.getLookAndFeel().getID())) { toolbarPanel.setBorder(BorderFactory.createEmptyBorder()); } else { toolbarPanel.setBorder(lowerBorder); } } }
/** * Paints the divider. */ public void paint(Graphics g) { super.paint(g); // Paint the border. Border border = getBorder(); if (border != null) { Dimension size = getSize(); border.paintBorder(this, g, 0, 0, size.width, size.height); } }
public void updateUI(VirtualFile baseDir) { this.baseDir = baseDir; tree.setCellRenderer(new CheckVersionCellRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); Color borderColor = new Color(46, 45, 45); status.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, borderColor)); Border outBorder = BorderFactory.createMatteBorder(0, 1, 0, 0, borderColor); Border inBorder = BorderFactory.createEmptyBorder(5, 5, 0, 0); tree.setBorder(BorderFactory.createCompoundBorder(outBorder, inBorder)); updateUI("Initializing..."); }
protected static AquaTableHeaderBorder getAquaBorderFrom(final JTableHeader header, final TableColumn column) { final TableCellRenderer renderer = column.getHeaderRenderer(); if (renderer == null) return null; final Component c = renderer.getTableCellRendererComponent(header.getTable(), column.getHeaderValue(), false, false, -1, column.getModelIndex()); if (!(c instanceof JComponent)) return null; final Border border = ((JComponent)c).getBorder(); if (!(border instanceof AquaTableHeaderBorder)) return null; return (AquaTableHeaderBorder)border; }
protected Border createRolloverBorder() { if (XPStyle.getXP() != null) { return new EmptyBorder(3, 3, 3, 3); } else { return super.createRolloverBorder(); } }
public void propertyChange(final PropertyChangeEvent evt) { if (!DIVIDER_PAINTER_KEY.equals(evt.getPropertyName())) return; final Object value = evt.getNewValue(); if (value instanceof Border) { divider.setBorder((Border)value); } else { divider.setBorder(null); } }