Java Code Examples for javax.swing.JComponent#getBorder()

The following examples show how to use javax.swing.JComponent#getBorder() . 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: SeaGlassIcon.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the icon's width. This is a cover methods for <code>
 * getIconWidth(null)</code>.
 *
 * @param  context the SynthContext describing the component/region, the
 *                 style, and the state.
 *
 * @return an int specifying the fixed width of the icon.
 */
@Override
public int getIconWidth(SynthContext context) {
    if (context == null) {
        return width;
    }

    JComponent c = context.getComponent();

    if (c instanceof JToolBar && ((JToolBar) c).getOrientation() == JToolBar.VERTICAL) {

        // we only do the -1 hack for UIResource borders, assuming
        // that the border is probably going to be our border
        if (c.getBorder() instanceof UIResource) {
            return c.getWidth() - 1;
        } else {
            return c.getWidth();
        }
    } else {
        return scale(context, width);
    }
}
 
Example 2
Source File: StatusBar.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds a new zone in the StatusBar
 * 
 * @param id
 * @param zone
 * @param constraints one of the constraint support by the
 *          {@link com.l2fprod.common.swing.PercentLayout}
 */
public void addZone(String id, Component zone, String constraints) {
  // is there already a zone with this id?
  Component previousZone = getZone(id);
  if (previousZone != null) {
    remove(previousZone);
    idToZones.remove(id);
  }

  if (zone instanceof JComponent) {
    JComponent jc = (JComponent)zone;
    if (jc.getBorder() == null || jc.getBorder() instanceof UIResource) {
      if (jc instanceof JLabel) {
        jc.setBorder(
          new CompoundBorder(zoneBorder, new EmptyBorder(0, 2, 0, 2)));
        ((JLabel)jc).setText(" ");
      } else {
        jc.setBorder(zoneBorder);
      }
    }
  }

  add(zone, constraints);
  idToZones.put(id, zone);
}
 
Example 3
Source File: ColorWellUI.java    From pumpernickel with MIT License 6 votes vote down vote up
@Override
public void paint(Graphics g0, JComponent c) {
	Graphics2D g = (Graphics2D) g0;
	JColorWell well = (JColorWell) c;
	Color color = well.getColorSelectionModel().getSelectedColor();
	Border border = c.getBorder();
	Insets borderInsets = border.getBorderInsets(c);
	if (color.getAlpha() < 255) {
		TexturePaint checkers = PlafPaintUtils.getCheckerBoard(8);
		g.setPaint(checkers);
		g.fillRect(borderInsets.left, borderInsets.top, c.getWidth()
				- borderInsets.left - borderInsets.right, c.getHeight()
				- borderInsets.top - borderInsets.bottom);
	}
	g.setColor(color);
	g.fillRect(borderInsets.left, borderInsets.top, c.getWidth()
			- borderInsets.left - borderInsets.right, c.getHeight()
			- borderInsets.top - borderInsets.bottom);
}
 
Example 4
Source File: DefaultPlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 */
private static JComponent wrapDialogContent(JComponent comp,
                                            boolean selfResizing) {
    JComponent result;
    
    if ((comp.getBorder() != null) || selfResizing) {
        result = selfResizing ? new SelfResizingPanel() : new JPanel();
        result.setLayout(new GridLayout());
        result.add(comp);
    } else {
        result = comp;
    }
    result.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
    result.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_title_select_generator"));
    return result;
}
 
Example 5
Source File: BEInternalFrameUI.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public void uninstallUI(JComponent c)
{
	frame = (JInternalFrame) c;

	Container cont = ((JInternalFrame) (c)).getContentPane();
	if (cont instanceof JComponent)
	{
		JComponent content = (JComponent) cont;
		if (content.getBorder() == handyEmptyBorder)
		{
			content.setBorder(null);
		}
	}
	super.uninstallUI(c);
}
 
Example 6
Source File: LuckFormattedTextFieldUI.java    From littleluck with Apache License 2.0 5 votes vote down vote up
public void installUI(JComponent c)
{
    super.installUI(c);

    if(c.getBorder() instanceof LuckShapeBorder)
    {
        installFocusListener(c);
    }
}
 
Example 7
Source File: ShadowPopupFactory.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * Reinitializes this ShadowPopup using the given parameters.
 *
 * @param newOwner component mouse coordinates are relative to, may be null
 * @param newContents the contents of the popup
 * @param newX the desired x location of the popup
 * @param newY the desired y location of the popup
 * @param newPopup the popup to wrap
 */
private void reset(Component newOwner, Component newContents, int newX, int newY,
		Popup newPopup) {
	this.owner = newOwner;
	this.contents = newContents;
	this.popup = newPopup;
	this.x = newX;
	this.y = newY;
	if (newOwner instanceof JComboBox) {
		return;
	}
	// Do not install the shadow border when the contents
	// has a preferred size less than or equal to 0.
	// We can't use the size, because it is(0, 0) for new popups.
	final Dimension contentsPrefSize = newContents.getPreferredSize();
	if (contentsPrefSize.width <= 0 || contentsPrefSize.height <= 0) {
		return;
	}
	for (Container p = newContents.getParent(); p != null; p = p.getParent()) {
		if (p instanceof JWindow || p instanceof Panel) {
			// Workaround for the gray rect problem.
			p.setBackground(newContents.getBackground());
			heavyWeightContainer = p;
			break;
		}
	}
	final JComponent parent = (JComponent) newContents.getParent();
	oldOpaque = parent.isOpaque();
	oldBorder = parent.getBorder();
	parent.setOpaque(false);
	parent.setBorder(SHADOW_BORDER);
	// Pack it because we have changed the border.
	if (heavyWeightContainer != null) {
		heavyWeightContainer.setSize(heavyWeightContainer.getPreferredSize());
	} else {
		parent.setSize(parent.getPreferredSize());
	}
}
 
Example 8
Source File: DataTable.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
  // value is column name
  String name = (value==null) ? "" : value.toString(); //$NON-NLS-1$
  textLine.setText(name);
  if (OSPRuntime.isMac()) {
  	name = TeXParser.removeSubscripting(name);
  }
  Component c = renderer.getTableCellRendererComponent(table, name, isSelected, hasFocus, row, col);
  if (!(c instanceof JComponent)) {
    return c;
  }
  JComponent comp = (JComponent) c;
  int sortCol = decorator.getSortedColumn();
  Font font = comp.getFont();
  if (OSPRuntime.isMac()) {
  	// textline doesn't work on OSX
    comp.setFont((sortCol!=convertColumnIndexToModel(col))? 
    		font.deriveFont(Font.PLAIN) : 
    		font.deriveFont(Font.BOLD));
    if (comp instanceof JLabel) {
    	((JLabel)comp).setHorizontalAlignment(SwingConstants.CENTER);
    }
    return comp;
  }
  java.awt.Dimension dim = comp.getPreferredSize();
  dim.height += 1;
  panel.setPreferredSize(dim);
  javax.swing.border.Border border = comp.getBorder();
  if (border instanceof javax.swing.border.EmptyBorder) {
    border = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
  }
  panel.setBorder(border);
  // set font: bold if sorted column
  textLine.setFont((sortCol!=convertColumnIndexToModel(col)) ? font : font.deriveFont(Font.BOLD));
  textLine.setColor(comp.getForeground());
  textLine.setBackground(comp.getBackground());
  panel.setBackground(comp.getBackground());
  return panel;
}
 
Example 9
Source File: SeaGlassStyleWrapper.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Re-implements SynthStyle.installDefaults(SynthContext, SynthUI) because
 * it's package local.
 *
 * @param context the context.
 * @param ui      the UI delegate.
 */
public void installDefaults(SeaGlassContext context, SeaglassUI ui) {
    // Special case the Border as this will likely change when the LAF
    // can have more control over this.
    if (!context.isSubregion()) {
        JComponent c      = context.getComponent();
        Border     border = c.getBorder();

        if (border == null || border instanceof UIResource) {
            c.setBorder(new SeaGlassBorder(ui, getInsets(context, null)));
        }
    }

    installDefaults(context);
}
 
Example 10
Source File: StyledToolTipUI.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paint(Graphics g, JComponent tooltip) {
	// Get rid of popup borders, if it has any (Heavy weight popups tend to
	// pack the tooltip in a JPanel
	Container parent = tooltip.getParent();
	if (parent instanceof JComponent) {
		JComponent popup = (JComponent) parent;
		if (popup.getBorder() != null) {
			popup.setBorder(null);
		}
	}
	super.paint(g, tooltip);
}
 
Example 11
Source File: GuiUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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
    }
}
 
Example 12
Source File: SeaGlassStyle.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Install UI defaults.
 *
 * @param context the SynthContext describing the component/regiont, the
 *                style, and the state.
 * @param ui      the UI delegate.
 */
public void installDefaults(SeaGlassContext context, SeaglassUI ui) {
    // Special case the Border as this will likely change when the LAF
    // can have more control over this.
    if (!context.isSubregion()) {
        JComponent c      = context.getComponent();
        Border     border = c.getBorder();

        if (border == null || border instanceof UIResource) {
            c.setBorder(new SeaGlassBorder(ui, getInsets(context, null)));
        }
    }

    installDefaults(context);
}
 
Example 13
Source File: FlatComboBoxUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
static void uninstall( Object o ) {
	if( o instanceof WeakReference )
		o = ((WeakReference<?>)o).get();

	if( !(o instanceof JComponent) )
		return;

	JComponent rendererComponent = (JComponent) o;
	Border border = rendererComponent.getBorder();
	if( border instanceof CellPaddingBorder ) {
		CellPaddingBorder paddingBorder = (CellPaddingBorder) border;
		rendererComponent.setBorder( paddingBorder.rendererBorder );
		paddingBorder.rendererBorder = null;
	}
}
 
Example 14
Source File: ValidationErrorsBalloonView.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
private static Border buildErrorBorder(JComponent component) {
	if (component.getBorder() == null) {
		return BorderFactory.createLineBorder(Color.RED, 1);
	} else {
		Insets borderInsets = component.getBorder().getBorderInsets(component);
		return BorderFactory.createMatteBorder(borderInsets.top, borderInsets.left, borderInsets.bottom,
				borderInsets.right, Color.RED);
	}
}
 
Example 15
Source File: BEInternalFrameUI.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
 * Strip content border.
 *
 * @param c the c
 */
private void stripContentBorder(Object c)
{
	if (c instanceof JComponent)
	{
		JComponent contentComp = (JComponent) c;
		Border contentBorder = contentComp.getBorder();
		if (contentBorder == null || contentBorder instanceof UIResource)
		{
			contentComp.setBorder(handyEmptyBorder);
		}
	}
}
 
Example 16
Source File: AquaColorWellUI.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public Dimension getPreferredSize(JComponent c) {
	Border border = c.getBorder();
	Insets i = border.getBorderInsets(c);
	return new Dimension(49 + i.left + i.right, 11 + i.top + i.bottom);
}
 
Example 17
Source File: DataToolTable.java    From osp with GNU General Public License v3.0 4 votes vote down vote up
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
  // value is data column name
  String realname = (value==null) ? "" : value.toString(); //$NON-NLS-1$
  String name = realname;
  if (OSPRuntime.isMac()) {
  	name = TeXParser.removeSubscripting(name);
  }
  Component c = renderer.getTableCellRendererComponent(table, name, isSelected, hasFocus, row, col);
  if (headerFont==null) headerFont = c.getFont();
  int labelCol = convertColumnIndexToView(0);
  int xCol = (labelCol==0) ? 1 : 0;
  int yCol = (labelCol<2) ? 2 : 1;
  if(unselectedBG==null) {
    unselectedBG = c.getBackground();
  }
  // backup color in case c has none
  if(unselectedBG==null) {
    unselectedBG = javax.swing.UIManager.getColor("Panel.background"); //$NON-NLS-1$
  }
  rowBG = dataToolTab.plot.getBackground();
  Color bgColor = (col==xCol)? DataToolTable.xAxisColor: 
  		(col==yCol)? DataToolTable.yAxisColor: rowBG;
  if(!(c instanceof JComponent)) {
    return c;
  }
  JComponent comp = (JComponent) c;
  
  java.awt.Dimension dim = comp.getPreferredSize();
  dim.height += 1;
  dim.height = Math.max(getRowHeight()+2, dim.height);
  panel.setPreferredSize(dim);
  javax.swing.border.Border border = comp.getBorder();
  if(border instanceof javax.swing.border.EmptyBorder) {
    border = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
  }
  panel.setBorder(border);
  
  // determine font: italics if undeletable, bold if sorted column
  Font font;
  Dataset data = getDataset(realname);
  if(!dataToolTab.isDeletable(data)) {
    font = getSortedColumn()!=convertColumnIndexToModel(col)? 
    		headerFont.deriveFont(Font.PLAIN+Font.ITALIC) : headerFont.deriveFont(Font.BOLD+Font.ITALIC);
  } else {
    font = getSortedColumn()!=convertColumnIndexToModel(col)? 
    		headerFont.deriveFont(Font.PLAIN) : headerFont.deriveFont(Font.BOLD);
  }
  int[] cols = getSelectedColumns();
  boolean selected = false;
  for(int i = 0; i<cols.length; i++) {
    selected = selected||(cols[i]==col);
  }
  selected = selected&&(convertColumnIndexToModel(col)>0);
  bgColor = selected? selectedHeaderBG: bgColor;
  
  // special case: textline doesn't work on OSX
  if (OSPRuntime.isMac()) {
    comp.setFont(font);
    comp.setBackground(bgColor);
    comp.setForeground(selected ? selectedHeaderFG : comp.getForeground());
    if (comp instanceof JLabel) {
    	((JLabel)comp).setHorizontalAlignment(SwingConstants.CENTER);
    }
    return comp;
  }

  textLine.setText(name);
  textLine.setFont(font);
  textLine.setColor(selected ? selectedHeaderFG : comp.getForeground());
  textLine.setBackground(bgColor);
  panel.setBackground(bgColor);
  return panel;
}
 
Example 18
Source File: TracerOptionsPanel.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private static void createBorder(JComponent component, Border border) {
    Border cBorder = component.getBorder();
    if (cBorder == null) component.setBorder(border);
    else component.setBorder(BorderFactory.createCompoundBorder(border, cBorder));
}
 
Example 19
Source File: JmxConnectionConfigurator.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private static void createBorder(JComponent component, Border border) {
    Border cBorder = component.getBorder();
    if (cBorder == null) component.setBorder(border);
    else component.setBorder(BorderFactory.createCompoundBorder(border, cBorder));
}
 
Example 20
Source File: Utility.java    From freecol with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Localize the a titled border.
 *
 * @param component The {@code JComponent} to localize.
 * @param template The {@code StringTemplate} to use.
 */
public static void localizeBorder(JComponent component,
                                  StringTemplate template) {
    TitledBorder tb = (TitledBorder)component.getBorder();
    tb.setTitle(Messages.message(template));
}