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

The following examples show how to use javax.swing.JComponent#setBorder() . 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: ShadowPopupFactory.java    From javamelody with Apache License 2.0 6 votes vote down vote up
/**
 * Hides and disposes of the <code>Popup</code>. Once a <code>Popup</code>
 * has been disposed you should no longer invoke methods on it. A
 * <code>dispose</code>d <code>Popup</code> may be reclaimed and later used
 * based on the <code>PopupFactory</code>. As such, if you invoke methods
 * on a <code>disposed</code> <code>Popup</code>, indeterminate
 * behavior will result.<p>
 *
 * In addition to the superclass behavior, we reset the stored
 * horizontal and vertical drop shadows - if any.
 */
@Override
public void hide() {
	if (contents == null) {
		return;
	}

	final JComponent parent = (JComponent) contents.getParent();
	popup.hide();
	if (parent != null && parent.getBorder() == SHADOW_BORDER) {
		parent.setBorder(oldBorder);
		parent.setOpaque(oldOpaque);
		oldBorder = null;
		if (heavyWeightContainer != null) {
			parent.putClientProperty(PROP_HORIZONTAL_BACKGROUND, null);
			parent.putClientProperty(PROP_VERTICAL_BACKGROUND, null);
			heavyWeightContainer = null;
		}
	}
	owner = null;
	contents = null;
	popup = null;
	recycle(this);
}
 
Example 2
Source File: StandardContentDialog.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form StandardDialog.
 *
 * @param parent Die Komponente, zu der der Dialog zentriert wird
 * @param content der Inhalt
 * @param modal ob der Dialog modal sein soll
 * @param options welche Schaltflächen angezeigt werden sollen
 */
public StandardContentDialog(Component parent,
                             DialogContent content,
                             boolean modal,
                             int options) {
  super(JOptionPane.getFrameForComponent(parent), modal);

  initComponents();
  initButtons(options);

  JComponent component = content.getComponent();

  if (component.getBorder() == null) {
    component.setBorder(new EmptyBorder(4, 4, 4, 4));
  }

  getContentPane().add(component, BorderLayout.CENTER);
  setTitle(content.getDialogTitle());
  content.initFields();
  pack();
  setLocationRelativeTo(parent);
  fContent = content;

  getRootPane().setDefaultButton(okButton);
}
 
Example 3
Source File: TitledPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public TitledPanel(JComponent titleComponent, JComponent bodyComponent, boolean isCollapsible, boolean isInitiallyCollapsed) {
    super(new BorderLayout());

    final JPanel titleArea = new JPanel(new BorderLayout());
    if (titleComponent != null) {
        titleArea.add(titleComponent, BorderLayout.WEST);
    }
    titleArea.add(getSeparator(), BorderLayout.CENTER);
    if (isCollapsible) {
        titleArea.add(getCollapseButton(bodyComponent, isInitiallyCollapsed), BorderLayout.EAST);
        bodyComponent.setVisible(!isInitiallyCollapsed);
    }
    add(titleArea, BorderLayout.NORTH);

    if (bodyComponent != null) {
        bodyComponent.setBorder(new EmptyBorder(0, 30, 0, 0));
        add(bodyComponent, BorderLayout.CENTER);
    }

    setBorder(new EmptyBorder(4, 8, 4, 8));
}
 
Example 4
Source File: DefaultTasksPanel.java    From opt4j with MIT License 6 votes vote down vote up
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
	Component c = super.prepareRenderer(renderer, row, column);
	Task task = executionEnvironment.getTasks().get(row);
	if (task.getException() == null) {
		c.setForeground(Color.BLACK);
	} else {
		c.setForeground(Color.RED);
	}

	if (c instanceof JComponent) {
		JComponent jc = (JComponent) c;
		jc.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));

		char[] chars = this.getValueAt(row, column).toString().toCharArray();
		int length = jc.getFontMetrics(jc.getFont()).charsWidth(chars, 0, chars.length);
		if (this.getColumnModel().getColumn(column).getWidth() < length) {
			jc.setToolTipText(format.formatTooltip(this.getValueAt(row, column).toString()));
		} else {
			jc.setToolTipText(null);
		}
	}

	return c;
}
 
Example 5
Source File: MaterialPopupMenuUI.java    From material-ui-swing with MIT License 5 votes vote down vote up
@Override
public void uninstallUI(JComponent c) {

	c.setFont (null);
	c.setBackground (null);
	c.setForeground (null);
	c.setBorder (null);
	c.setCursor(null);

	super.uninstallUI(c);
}
 
Example 6
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private JComponent createHintComponent(@NotNull String text,
    @NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition,
    final Editor editor,
    @NotNull final Runnable cancelAction,
    final int maxUsages,
    @NotNull final FindUsagesOptions options) {
  JComponent label = HintUtil.createInformationLabel(suggestSecondInvocation(options, handler, text + "&nbsp;"));
  InplaceButton button = createSettingsButton(handler, popupPosition, editor, maxUsages, cancelAction);

  JPanel panel = new JPanel(new BorderLayout()) {
    @Override
    public void addNotify() {
      mySearchEverywhereRunnable = new Runnable() {
        @Override
        public void run() {
          searchEverywhere(options, handler, editor, popupPosition, maxUsages);
        }
      };
      super.addNotify();
    }

    @Override
    public void removeNotify() {
      mySearchEverywhereRunnable = null;
      super.removeNotify();
    }
  };
  button.setBackground(label.getBackground());
  panel.setBackground(label.getBackground());
  label.setOpaque(false);
  label.setBorder(null);
  panel.setBorder(HintUtil.createHintBorder());
  panel.add(label, BorderLayout.CENTER);
  panel.add(button, BorderLayout.EAST);
  return panel;
}
 
Example 7
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 8
Source File: AnimationController.java    From pumpernickel with MIT License 5 votes vote down vote up
private static void setInsetFocusBorder(JComponent jc) {
	Border oldBorder = jc.getBorder();
	Border newBorder = new FocusInsetBorder(jc);
	if (oldBorder == null) {
		jc.setBorder(oldBorder);
	} else {
		jc.setBorder(new CompoundBorder(oldBorder, newBorder));
	}
}
 
Example 9
Source File: SettlersDynamicLabelUi.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	c.setForeground(foregroundColor);
	c.setBorder(border);
	c.setFont(UIDefaults.FONT);
}
 
Example 10
Source File: NotificationImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void initDecorations() {
    if (null != detailsText) {
        balloonComp = createDetails(detailsText, al);
        detailsComp = createDetails(detailsText, al);
    }

    JComponent titleComp = createTitle(title, icon);
    JComponent balloon = createContent(titleComp, balloonComp);
    balloon.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0));
    balloonComp = balloon;

    titleComp = createTitle(title, icon);
    detailsComp = createContent(titleComp, detailsComp, createPriority(priority), createCategory(category), createDate(dateCreated));
}
 
Example 11
Source File: UIUtil.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Nullify the border of this JComponent, as well as its subcomponents.
 *
 * @param comp top of hierarchy
 */
public static void suppressBorders (JComponent comp)
{
    if (!(comp instanceof JButton) && !(comp instanceof JToggleButton)) {
        comp.setBorder(null);
    }

    suppressBorders((Container) comp);
}
 
Example 12
Source File: Table.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public boolean stopCellEditing() {
   try {
      return super.stopCellEditing();
   }
   catch(Exception e) {
      JComponent c = (JComponent) getComponent();
      c.setBorder(new LineBorder(Color.RED));
      Oculus.warn("Invalid value for cell: " + e.getMessage() + "\nClick 'esc' to stop editing", e);
      return false;
   }
}
 
Example 13
Source File: StyledMenuItemUI.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void installUI(JComponent component) {
	super.installUI(component);

	component.setBorder(style.getBorder());
	component.setOpaque(false);
	component.setFont(style.getFont());
	component.setForeground(style.getForeground());
}
 
Example 14
Source File: CardsJTable.java    From magarena with GNU General Public License v3.0 4 votes vote down vote up
/******************************************************************
 * TRANSLUCENT THEME
 ******************************************************************/

//
// default cell renderer
//
private Component prepareThemedRenderer(TableCellRenderer renderer, int row, int column) {

    final Component cell = super.prepareRenderer(renderer, row, column);
    final MagicCardDefinition card = tableModel.getCardDef(row);
    final boolean isRowSelected = isRowSelected(row);

    /*
    Set text color.
    */
    cell.setForeground(card.isInvalid()
            ? Color.GRAY
            : ColorHelper.getOppositeColor(defaultForeColor)
    );

    /*
    default cell properties
    */
    final int ordinal = convertColumnIndexToModel(column);
    if (CardTableColumn.values()[ordinal] != CardTableColumn.Cost) {
        if (cell instanceof JComponent) {
            final JComponent jc = (JComponent) cell;
            jc.setBorder(isRowSelected ? SELECTED_BORDER : NO_FOCUS_BORDER);
            jc.setOpaque(false);
        }
    }


    /*
    Highlight row on mouse over.
    */
    if (row == mouseOverRow) {
        cell.setForeground(MagicStyle.getRolloverColor());
    }

    return cell;
}
 
Example 15
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 16
Source File: ImageHelper.java    From magarena with GNU General Public License v3.0 4 votes vote down vote up
public static void setDebugBorder(final JComponent component) {
    component.setBorder(BorderFactory.createDashedBorder(debugBorderPaint));
}
 
Example 17
Source File: LookAndFeelTweaks.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public static void setBorder(JComponent component) {
  if (component instanceof JPanel) {
    component.setBorder(PANEL_BORDER);
  }
}
 
Example 18
Source File: AbstractRenderer.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
protected void setEmpty(JComponent comp) {
    comp.setBorder(errorBorder);
    comp.setToolTipText(empty);
}
 
Example 19
Source File: OverviewBuilder.java    From raccoon4 with Apache License 2.0 4 votes vote down vote up
@Override
protected JPanel assemble() {
	border = new EmptyBorder(10, 5, 5, 5);
	titleStrip = new TitleStrip("", "", TitleStrip.BLANK);
	URL feed = null;
	try {
		feed = Bookmarks.SHOUTBOXFEED.toURL();
	}
	catch (MalformedURLException e) {
	}
	AbstractPanelBuilder shouts = new SyndicationBuilder(Messages.getString(ID
			+ ".shoutfeed"), feed).withBorder(border);
	titleStrip.setSubTitle(Messages.getString(ID + ".waitadb"));

	versionPanel = new JPanel(false);
	versionPanel.setVisible(false);
	adbPanel = new JPanel(false);
	adbPanel.setVisible(false);

	JComponent plugPanel;
	if (showPlug()) {
		InfoBuilder plug = new InfoBuilder(Messages.getString(ID + ".plug.title"))
				.withTitleColor(Color.RED.darker());
		plugPanel = plug.build(globals);
		plug.setInfo(MessageFormat.format(
				Messages.getString(ID + ".plug.message"), Bookmarks.FEATURELIST,
				Bookmarks.ORDER));
		plugPanel.setBorder(border);
	}
	else {
		plugPanel = Box.createVerticalBox();
	}

	JPanel ret = new JPanel();
	ret.setLayout(new GridBagLayout());
	GridBagConstraints gbc = new GridBagConstraints();
	gbc.gridx = 0;
	gbc.gridy = 0;
	gbc.anchor = GridBagConstraints.NORTHWEST;
	gbc.fill = GridBagConstraints.HORIZONTAL;

	ret.add(titleStrip, gbc);

	gbc.gridy++;
	ret.add(plugPanel, gbc);

	gbc.gridy++;
	ret.add(versionPanel, gbc);

	gbc.gridy++;
	ret.add(adbPanel, gbc);

	gbc.gridy++;
	gbc.fill = GridBagConstraints.BOTH;
	gbc.weightx = 1;
	gbc.weighty = 1;
	ret.add(shouts.build(globals), gbc);

	DatabaseManager dbm = globals.get(DatabaseManager.class);
	PlayProfileDao dao = dbm.get(PlayProfileDao.class);
	PlayProfile pp = dao.get();
	if (pp != null) {
		titleStrip.setTitle(MessageFormat.format(
				Messages.getString(ID + ".welcome"), pp.getAlias()));
	}

	globals.get(BridgeManager.class).addBridgeListener(this);
	dao.addDataSetListener(new DatasetListenerProxy(this));
	new VersionWorker(this).execute();
	return ret;
}
 
Example 20
Source File: GUIUtils.java    From mzmine3 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Add a margin to a given component
 *
 * @param component Component to add the margin to
 * @param margin Margin size
 * @return Created border
 */
public static Border addMargin(JComponent component, int margin) {
  Border marginBorder = BorderFactory.createEmptyBorder(margin, margin, margin, margin);
  component.setBorder(marginBorder);
  return marginBorder;
}