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

The following are Jave code examples for showing how to use getBorder() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: DefaultPlugin.java   View Source Code Vote up 6 votes
/**
 */
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 2
Project: VASSAL-src   File: WizardDisplayerImpl.java   View Source Code Vote up 6 votes
void handleSummary(Summary summary)
{
    inSummary = true;
    JComponent summaryComp = (JComponent) summary.getSummaryComponent(); // XXX
    if (summaryComp.getBorder() != null)
    {
        CompoundBorder b = new CompoundBorder(new EmptyBorder(5, 5, 5, 5), summaryComp
            .getBorder());
        summaryComp.setBorder(b);
    }
    setCurrentWizardPanel(summaryComp); // XXX
    instructions.setInSummaryPage(true);
    ttlLabel.setText(NbBridge.getString("org/netbeans/api/wizard/Bundle", // NOI18N
                                        WizardDisplayerImpl.class, "Summary")); // NOI18N
    getButtonManager().setSummaryShowingMode();
    summaryComp.requestFocus();
    
}
 
Example 3
Project: Neukoelln_SER316   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 5 votes
private void applyFocus(boolean hasFocus, JComponent c) {
    if (hasFocus) {
        c.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, table.getSelectionBackground()
                .darker()));
    } else {
        if (c.getBorder() != null) {
            c.setBorder(null);
        }
    }
}
 
Example 4
Project: incubator-netbeans   File: RendererPropertyDisplayer.java   View Source Code Vote up 5 votes
JComponent getRenderer(PropertyDisplayer_Inline inline) {
    inGetRenderer = true;

    JComponent result = rfactory(inline).getRenderer(inline.getProperty());

    if (inline.isTableUI() && null == result.getBorder() ) {
        //Actually want an empty border, not null - some components treat
        //a null border as an invitation to improvise
        result.setBorder(BorderFactory.createEmptyBorder());
    }

    inGetRenderer = false;

    return result;
}
 
Example 5
Project: SER316-Aachen   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 5 votes
private void applyFocus(boolean hasFocus, JComponent c) {
    if (hasFocus) {
        c.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, table.getSelectionBackground()
                .darker()));
    } else {
        if (c.getBorder() != null) {
            c.setBorder(null);
        }
    }
}
 
Example 6
Project: Reinickendorf_SER316   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 5 votes
private void applyFocus(boolean hasFocus, JComponent c) {
    if (hasFocus) {
        c.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, table.getSelectionBackground()
                .darker()));
    } else {
        if (c.getBorder() != null) {
            c.setBorder(null);
        }
    }
}
 
Example 7
Project: incubator-netbeans   File: AdvancedPanel.java   View Source Code Vote up 5 votes
private void handleTabSwitched(String searchText, List<String> matchedKeywords) {
      final int selectedIndex = tabbedPanel.getSelectedIndex() >= 0 ? tabbedPanel.getSelectedIndex() : -1;
      if (selectedIndex != -1) {
          String category = tabbedPanel.getTitleAt(selectedIndex);
          if (tabbedPanel.getSelectedComponent() instanceof JLabel) {
              JComponent panel = model.getPanel(category);
              if( null == panel.getBorder() ) {
                  panel.setBorder(BorderFactory.createEmptyBorder(11,11,11,11));
              }
              JScrollPane scroll = new JScrollPane(panel);
              scroll.setOpaque(false);
              scroll.getViewport().setOpaque(false);
              scroll.setBorder(BorderFactory.createEmptyBorder());
              scroll.getVerticalScrollBar().setUnitIncrement(Utils.ScrollBarUnitIncrement);
              scroll.getHorizontalScrollBar().setUnitIncrement(Utils.ScrollBarUnitIncrement);
              tabbedPanel.setComponentAt(tabbedPanel.getSelectedIndex(), scroll);
          }
          model.update(category);
          if (searchText != null && matchedKeywords != null) {
OptionsPanelController controller = model.getController(model.getID(category));
if(controller == null) {
    LOGGER.log(Level.WARNING, "No controller found for category: {0}", category);  //NOI18N
} else {
    controller.handleSuccessfulSearch(searchText, matchedKeywords);
}
          }
          firePropertyChange (OptionsPanelController.PROP_HELP_CTX, null, null);        
      }
  }
 
Example 8
Project: incubator-netbeans   File: GuiUtils.java   View Source Code Vote up 5 votes
/**
 * 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 9
Project: Moenagade   File: LayoutStyle.java   View Source Code Vote up 5 votes
private int getCBRBPadding(JComponent c, int position) {
    if (c.getUIClassID() == "CheckBoxUI" ||
          c.getUIClassID() == "RadioButtonUI") {
        Border border = c.getBorder();
        if (border instanceof UIResource) {
            return getInset(c, position);
        }
    }
    return 0;
}
 
Example 10
Project: SER316-Munich   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 5 votes
private void applyFocus(boolean hasFocus, JComponent c) {
    if (hasFocus) {
        c.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, table.getSelectionBackground()
                .darker()));
    } else {
        if (c.getBorder() != null) {
            c.setBorder(null);
        }
    }
}
 
Example 11
Project: Wilmersdorf_SER316   File: TaskTreeTableCellRenderer.java   View Source Code Vote up 5 votes
private void applyFocus(boolean hasFocus, JComponent c) {
    if (hasFocus) {
        c.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, table.getSelectionBackground()
                .darker()));
    } else {
        if (c.getBorder() != null) {
            c.setBorder(null);
        }
    }
}
 
Example 12
Project: Cognizant-Intelligent-Test-Scripter   File: Listeners.java   View Source Code Vote up 5 votes
@Override
public void mouseExited(MouseEvent e) {
    JComponent now = (JComponent) e.getSource();
    if (now.getBorder() != Border.thumbPrevSelected) {
        now.setBorder(thumbPrevOffFocus);
    }
}
 
Example 13
Project: incubator-netbeans   File: TracerOptionsPanel.java   View Source Code Vote up 4 votes
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 14
Project: incubator-netbeans   File: MethodsFeatureModes.java   View Source Code Vote up 4 votes
private static Component createStrut(JComponent c, int width, boolean before) {
    Border b = c.getBorder();
    Insets i = b != null ? b.getBorderInsets(c) : null;
    int w = i == null ? width : Math.max(width - (before ? i.left : i.right), 0);
    return Box.createHorizontalStrut(w);
}
 
Example 15
Project: incubator-netbeans   File: TabbedController.java   View Source Code Vote up 4 votes
/** Replace placeholder with real panel and change help context. */
  private void handleTabSwitched(String searchText, List<String> matchedKeywords) {
      final int selectedIndex = pane.getSelectedIndex();
      if (selectedIndex != -1) {
          String tabTitle = pane.getTitleAt(selectedIndex);
          OptionsPanelController controller = tabTitle2controller.get(tabTitle);
          if (pane.getSelectedComponent() instanceof JLabel) {
              JComponent comp;
              if (controller == null) {
                  AdvancedOption advancedOption = tabTitle2Option.get(tabTitle);
                  if (advancedOption == null) {
                      LOGGER.log(Level.INFO, "AdvancedOption for {0} is not present.", tabTitle);
                      return;
                  } else {
                      controller = advancedOption.create();
                      tabTitle2controller.put(tabTitle, controller);
                      // must be here because many controllers rely on fact that getComponent() is called first than other methods
                      comp = controller.getComponent(masterLookup);
                      // add existing listeners
                      for (PropertyChangeListener pcl : pcs.getPropertyChangeListeners()) {
                          controller.addPropertyChangeListener(pcl);
                      }
                  }
              } else {
                  comp = controller.getComponent(masterLookup);
              }
              if( null == comp.getBorder() ) {
                  comp.setBorder(BorderFactory.createEmptyBorder(11,11,11,11));
              }
              JScrollPane scroll = new JScrollPane(comp);
              scroll.setBorder(BorderFactory.createEmptyBorder());
              scroll.setOpaque(false);
              scroll.getViewport().setOpaque(false);
              scroll.getVerticalScrollBar().setUnitIncrement(Utils.ScrollBarUnitIncrement);
              scroll.getHorizontalScrollBar().setUnitIncrement(Utils.ScrollBarUnitIncrement);
              pane.setComponentAt(selectedIndex, scroll);
              controller.update();
controller.isValid();
          }
   if (searchText != null && matchedKeywords != null) {
controller.handleSuccessfulSearch(searchText, matchedKeywords);
          }
          pcs.firePropertyChange(OptionsPanelController.PROP_HELP_CTX, null, null);
      }
  }
 
Example 16
Project: incubator-netbeans   File: ProfilerOptionsContainer.java   View Source Code Vote up 4 votes
private static void enlargeBorder(JComponent c, int t, int l, int b, int r) {
    Border current = c.getBorder();
    Border larger = BorderFactory.createEmptyBorder(t, l, b, r);
    if (current == null) c.setBorder(larger);
    else c.setBorder(BorderFactory.createCompoundBorder(larger, current));
}
 
Example 17
Project: freecol   File: Canvas.java   View Source Code Vote up 4 votes
/**
 * Adds a component on this Canvas inside a frame.
 *
 * @param comp The component to add to the canvas.
 * @param toolBox Should be set to true if the resulting frame is
 *     used as a toolbox (that is: it should not be counted as a
 *     frame).
 * @param popupPosition A preferred {@code PopupPosition}.
 * @param resizable Whether this component can be resized.
 * @return The {@code JInternalFrame} that was created and added.
 */
private JInternalFrame addAsFrame(JComponent comp, boolean toolBox,
                                  PopupPosition popupPosition,
                                  boolean resizable) {
    final int FRAME_EMPTY_SPACE = 60;

    final JInternalFrame f = (toolBox) ? new ToolBoxFrame()
        : new JInternalFrame();
    if (f.getContentPane() instanceof JComponent) {
        JComponent c = (JComponent) f.getContentPane();
        c.setOpaque(false);
        c.setBorder(null);
    }

    if (comp.getBorder() != null) {
        if (comp.getBorder() instanceof EmptyBorder) {
            f.setBorder(Utility.blankBorder(10, 10, 10, 10));
        } else {
            f.setBorder(comp.getBorder());
            comp.setBorder(Utility.blankBorder(5, 5, 5, 5));
        }
    } else {
        f.setBorder(null);
    }

    final FrameMotionListener fml = new FrameMotionListener(f);
    comp.addMouseMotionListener(fml);
    comp.addMouseListener(fml);
    if (f.getUI() instanceof BasicInternalFrameUI) {
        BasicInternalFrameUI biu = (BasicInternalFrameUI) f.getUI();
        biu.setNorthPane(null);
        biu.setSouthPane(null);
        biu.setWestPane(null);
        biu.setEastPane(null);
    }

    f.getContentPane().add(comp);
    f.setOpaque(false);
    f.pack();
    int width = f.getWidth();
    int height = f.getHeight();
    if (width > getWidth() - FRAME_EMPTY_SPACE) {
        width = Math.min(width, getWidth());
    }
    if (height > getHeight() - FRAME_EMPTY_SPACE) {
        height = Math.min(height, getHeight());
    }
    f.setSize(width, height);
    Point p = chooseLocation(comp, width, height, popupPosition);
    f.setLocation(p);
    this.add(f, MODAL_LAYER);
    f.setName(comp.getClass().getSimpleName());

    f.setFrameIcon(null);
    f.setVisible(true);
    f.setResizable(resizable);
    try {
        f.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}

    return f;
}
 
Example 18
Project: FreeCol   File: Canvas.java   View Source Code Vote up 4 votes
/**
 * Adds a component on this Canvas inside a frame.
 *
 * @param comp The component to add to the canvas.
 * @param toolBox Should be set to true if the resulting frame is
 *     used as a toolbox (that is: it should not be counted as a
 *     frame).
 * @param popupPosition A preferred {@code PopupPosition}.
 * @param resizable Whether this component can be resized.
 * @return The {@code JInternalFrame} that was created and added.
 */
private JInternalFrame addAsFrame(JComponent comp, boolean toolBox,
                                  PopupPosition popupPosition,
                                  boolean resizable) {
    final int FRAME_EMPTY_SPACE = 60;

    final JInternalFrame f = (toolBox) ? new ToolBoxFrame()
        : new JInternalFrame();
    if (f.getContentPane() instanceof JComponent) {
        JComponent c = (JComponent) f.getContentPane();
        c.setOpaque(false);
        c.setBorder(null);
    }

    if (comp.getBorder() != null) {
        if (comp.getBorder() instanceof EmptyBorder) {
            f.setBorder(Utility.blankBorder(10, 10, 10, 10));
        } else {
            f.setBorder(comp.getBorder());
            comp.setBorder(Utility.blankBorder(5, 5, 5, 5));
        }
    } else {
        f.setBorder(null);
    }

    final FrameMotionListener fml = new FrameMotionListener(f);
    comp.addMouseMotionListener(fml);
    comp.addMouseListener(fml);
    if (f.getUI() instanceof BasicInternalFrameUI) {
        BasicInternalFrameUI biu = (BasicInternalFrameUI) f.getUI();
        biu.setNorthPane(null);
        biu.setSouthPane(null);
        biu.setWestPane(null);
        biu.setEastPane(null);
    }

    f.getContentPane().add(comp);
    f.setOpaque(false);
    f.pack();
    int width = f.getWidth();
    int height = f.getHeight();
    if (width > getWidth() - FRAME_EMPTY_SPACE) {
        width = Math.min(width, getWidth());
    }
    if (height > getHeight() - FRAME_EMPTY_SPACE) {
        height = Math.min(height, getHeight());
    }
    f.setSize(width, height);
    Point p = chooseLocation(comp, width, height, popupPosition);
    f.setLocation(p);
    this.add(f, MODAL_LAYER);
    f.setName(comp.getClass().getSimpleName());

    f.setFrameIcon(null);
    f.setVisible(true);
    f.setResizable(resizable);
    try {
        f.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}

    return f;
}
 
Example 19
Project: FreeCol   File: Utility.java   View Source Code Vote up 2 votes
/**
 * 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));
}
 
Example 20
Project: freecol   File: Utility.java   View Source Code Vote up 2 votes
/**
 * 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));
}