Java Code Examples for javax.swing.JComponent#getBackground()
The following examples show how to use
javax.swing.JComponent#getBackground() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlatTaskPaneUI.java From FlatLaf with Apache License 2.0 | 6 votes |
@Override protected void installDefaults() { if( group.getContentPane() instanceof JComponent ) { // remove default SwingX content border, which may be still set when switching LaF JComponent content = (JComponent) group.getContentPane(); Border contentBorder = content.getBorder(); if( contentBorder instanceof CompoundBorder && ((CompoundBorder)contentBorder).getOutsideBorder() instanceof BasicTaskPaneUI.ContentPaneBorder && ((CompoundBorder)contentBorder).getInsideBorder() instanceof EmptyBorder ) { content.setBorder( null ); } // set non-UIResource color to background to avoid that it is lost when switching LaF background = UIManager.getColor( "TaskPane.background" ); Color bg = content.getBackground(); if( bg == null || bg instanceof UIResource ) { content.setBackground( new Color( background.getRGB(), true ) ); } } roundHeight = FlatUIUtils.getUIInt( "TaskPane.roundHeight", UIManager.getInt( "Component.arc" ) ); super.installDefaults(); }
Example 2
Source File: FlatRadioButtonUI.java From FlatLaf with Apache License 2.0 | 5 votes |
@Override public void paint( Graphics g, JComponent c ) { // fill background even if not opaque if // - contentAreaFilled is true and // - if background was explicitly set to a non-UIResource color if( !c.isOpaque() && ((AbstractButton)c).isContentAreaFilled() && !(c.getBackground() instanceof UIResource) ) { g.setColor( c.getBackground() ); g.fillRect( 0, 0, c.getWidth(), c.getHeight() ); } // small insets fix int focusWidth = getIconFocusWidth( c ); if( focusWidth > 0 ) { boolean ltr = c.getComponentOrientation().isLeftToRight(); Insets insets = c.getInsets( tempInsets ); int leftOrRightInset = ltr ? insets.left : insets.right; if( focusWidth > leftOrRightInset ) { // The left (or right) inset is smaller than the focus width, which may be // the case if insets were explicitly reduced (e.g. with an EmptyBorder). // In this case the width has been increased in getPreferredSize() and // here it is necessary to fix icon and text painting location. int offset = focusWidth - leftOrRightInset; if( !ltr ) offset = -offset; // move the graphics origin to the left (or right) g.translate( offset, 0 ); super.paint( g, c ); g.translate( -offset, 0 ); return; } } super.paint( FlatLabelUI.createGraphicsHTMLTextYCorrection( g, c ), c ); }
Example 3
Source File: FlatButtonUI.java From FlatLaf with Apache License 2.0 | 5 votes |
protected Color getBackgroundBase( JComponent c, boolean def ) { // use component background if explicitly set Color bg = c.getBackground(); if( isCustomBackground( bg ) ) return bg; return def ? defaultBackground : bg; }
Example 4
Source File: ViewUtil.java From netbeans with Apache License 2.0 | 5 votes |
/** * Change background of given component to light gray on Mac look and feel * when the component is in a tabbed container and its background hasn't been * already changed (is instance of UIResource). * @param c */ static void adjustBackground( JComponent c ) { if( !isAquaLaF || useDefaultBackground ) return; if( !isInTabbedContainer(c) ) return; Color currentBackground = c.getBackground(); if( currentBackground instanceof UIResource ) { c.setBackground(UIManager.getColor("NbExplorerView.background")); } }
Example 5
Source File: WinClassicViewTabDisplayerUI.java From netbeans with Apache License 2.0 | 5 votes |
/** * adds painting of overall border */ @Override public void paint(Graphics g, JComponent c) { ColorUtil.setupAntialiasing(g); Color col = c.getBackground(); if (col != null) { g.setColor (col); g.fillRect (0, 0, c.getWidth(), c.getHeight()); } paintOverallBorder(g, c); super.paint(g, c); }
Example 6
Source File: LabelCellRenderer.java From pumpernickel with MIT License | 5 votes |
protected void formatLabelColors(JComponent jc, boolean isSelected, int rowNumber) { if (comboBox != null) { if (isSelected) { label.setBackground(UIManager .getColor("ComboBox.selectionBackground")); label.setForeground(UIManager .getColor("ComboBox.selectionForeground")); } else { label.setBackground(UIManager.getColor("ComboBox.background")); label.setForeground(UIManager.getColor("ComboBox.foreground")); } } else { if (isSelected) { if (jc instanceof JList) { label.setBackground(UIManager .getColor("List.selectionBackground")); label.setForeground(UIManager .getColor("List.selectionForeground")); } else { label.setBackground(UIManager .getColor("Menu.selectionBackground")); label.setForeground(UIManager .getColor("Menu.selectionForeground")); } } else { Color background; if (jc != null) { background = jc.getBackground(); if (rowNumber % 2 == 1 && isAlternatingBackround(jc)) { background = darken(background); } } else { background = UIManager.getColor("Menu.background"); } label.setBackground(background); label.setForeground(UIManager.getColor("Menu.foreground")); } } }
Example 7
Source File: PGTUtil.java From PolyGlot with MIT License | 4 votes |
/** * gets a worker that can make a given component flash * * @param flashMe component to make flash * @param flashColor color to use for flashing * @param isBack whether display color is background (rather than foreground) * @return SwingWorker that will make given component flash if run */ public static SwingWorker getFlashWorker(final JComponent flashMe, final Color flashColor, final boolean isBack) { // this will pop out in its own little thread... return new SwingWorker() { @Override protected Object doInBackground() { Color originColor; if (isBack) { originColor = flashMe.getBackground(); } else { originColor = flashMe.getForeground(); } Color requiredColor = flashColor.equals(originColor) ? Color.white : flashColor; try { for (int i = 0; i < PGTUtil.NUM_MENU_FLASHES; i++) { if (isBack) { flashMe.setBackground(requiredColor); } else { flashMe.setEnabled(false); } // suppression for this is broken. Super annoying. Thread.sleep(PGTUtil.MENU_FLASH_SLEEP); if (isBack) { flashMe.setBackground(originColor); } else { flashMe.setEnabled(true); } Thread.sleep(PGTUtil.MENU_FLASH_SLEEP); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); // catch of thread interrupt not logworthy // IOHandler.writeErrorLog(e); } return null; } }; }
Example 8
Source File: LoweredBorder.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 9
Source File: LoweredBorder.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 10
Source File: LoweredBorder.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 11
Source File: LoweredBorder.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 12
Source File: LoweredBorder.java From Bytecoder with Apache License 2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 13
Source File: LoweredBorder.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 14
Source File: Coloring.java From netbeans with Apache License 2.0 | 4 votes |
/** Apply this coloring to component colors/font. * The underline and strikeThrough line colors have no effect here. */ public void apply(JComponent c) { // Possibly change font if (font != null) { if (fontMode == FONT_MODE_DEFAULT) { c.setFont(font); } else { // non-default font-mode Font origFont = c.getFont(); if (origFont != null) { synchronized (cacheLock) { Font f = (Font)fontAndForeColorCache.get(origFont); if (f == null) { f = modifyFont(origFont); fontAndForeColorCache.put(origFont, f); } c.setFont(f); } } } } // Possibly change fore-color if (foreColor != null) { if (!hasAlpha(foreColor)) { c.setForeground(foreColor); } else { // non-default fore color-mode Color origForeColor = c.getForeground(); if (origForeColor != null) { synchronized (cacheLock) { Color fc = (Color)fontAndForeColorCache.get(origForeColor); if (fc == null) { fc = modifyForeColor(origForeColor); fontAndForeColorCache.put(origForeColor, fc); } c.setForeground(fc); } } } } // Possibly change back-color if (backColor != null) { if (!hasAlpha(backColor)) { c.setBackground(backColor); } else { // non-default back color-mode Color origBackColor = c.getBackground(); if (origBackColor != null) { synchronized (cacheLock) { Color bc = (Color)backColorCache.get(origBackColor); if (bc == null) { bc = modifyBackColor(origBackColor); backColorCache.put(origBackColor, bc); } c.setBackground(bc); } } } } }
Example 15
Source File: LoweredBorder.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 16
Source File: LoweredBorder.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 17
Source File: LoweredBorder.java From JDKSourceCode1.8 with MIT License | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 18
Source File: LoweredBorder.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 19
Source File: LoweredBorder.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Override protected Object[] getExtendedCacheKeys(JComponent c) { return (c != null) ? new Object[] { c.getBackground() } : null; }
Example 20
Source File: MaterialUIMovement.java From material-ui-swing with MIT License | 3 votes |
/** * Thie method create a new effect mouse hover static, not create a wake effect * This method is util in all component for click, an example: The button for JSpinner, JCombobox, JScroolbar * @param c is the component * @param colorEffect is the color for effect, (For using color, look the MaterialColors class) * @param colorOnClick is the color of the component on click on it * @return a new MaterialUIStaticMovement this class implement a only MouseListner for moment * @author https://github.com/vincenzopalazzo */ public static MaterialUIStaticMovement getStaticMovement(JComponent c, Color colorEffect, Color colorOnClick){ if(c == null || colorEffect == null || colorOnClick == null){ throw new IllegalArgumentException("Che input arguments is/are null"); } return new MaterialUIStaticMovement(c.getBackground(), colorEffect, colorOnClick); }