javax.swing.JComponent.setBorder()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中javax.swing.JComponent.setBorder()方法的一些代码示例,展示了JComponent.setBorder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComponent.setBorder()方法的具体详情如下:
包路径:javax.swing.JComponent
类名称:JComponent
方法名:setBorder

JComponent.setBorder介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private JFrame frame = new JFrame("Test");
private JPanel panel = new JPanel();
private JLabel label = new JLabel("CenteredJLabel");
  panel.add(label);
  panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  frame.add(panel);
  frame.setSize(400, 300);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

setBorder(BorderFactory.createCompoundBorder(
   BorderFactory.createTitledBorder("Player Editor"),
   BorderFactory.createEmptyBorder(5, 5, 5, 5)));
  FieldTitle fieldTitle = FieldTitle.values()[i];
  gbc = createGbc(0, i);
  add(new JLabel(fieldTitle.getTitle() + ":", JLabel.LEFT), gbc);
  gbc = createGbc(1, i);
  JTextField textField = new JTextField(10);
  add(textField, gbc);

代码示例来源:origin: stackoverflow.com

JPanel gui = new JPanel(new GridLayout(2,0,5,5));
gui.setBorder(new EmptyBorder(10,10,10,10));
gui.setBackground(Color.RED);
l1.setBorder(brdrRight);
gui.add(l1);
l2.setBorder(brdrLeft);
l2.setBackground(Color.YELLOW);
l2.setOpaque(true);
gui.add(l2);
JPanel p1 = new JPanel();
p1.add(new JLabel("Panel 1"));
p1.setBorder(brdrRight);
p1.setOpaque(false);
gui.add(p1);
JPanel p2 = new JPanel();
p2.add(new JLabel("Panel 2"));
p2.setBorder(brdrLeft);
gui.add(p2);

代码示例来源:origin: camunda/camunda-bpm-platform

getContentPane().add(cp, BorderLayout.NORTH);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
final JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBorder(BorderFactory.createTitledBorder("Events: "));
scrollPane.setPreferredSize(new Dimension(900, 300));
getContentPane().add(jsp, BorderLayout.CENTER);
pack();
setVisible(true);

代码示例来源:origin: stackoverflow.com

final JPanel gui = new JPanel(new BorderLayout(5,5));
gui.setBorder( new TitledBorder("BorderLayout(5,5)") );
JPanel plafComponents = new JPanel(
  new FlowLayout(FlowLayout.RIGHT, 3,3));
plafComponents.setBorder(
  new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)") );
plafComponents.add(plafChooser);
plafComponents.add(pack);
gui.add(plafComponents, BorderLayout.NORTH);
JPanel dynamicLabels = new JPanel(new BorderLayout(4,4));
dynamicLabels.setBorder(
  new TitledBorder("BorderLayout(4,4)") );
gui.add(dynamicLabels, BorderLayout.WEST);
final JPanel labels = new JPanel(new GridLayout(0,2,3,3));
labels.setBorder(
  new TitledBorder("GridLayout(0,2,3,3)") );
JPanel imagePanel = new JPanel(new GridBagLayout());
imagePanel.setBorder(
  new TitledBorder("GridBagLayout()") );
frame.pack();

代码示例来源:origin: camunda/camunda-bpm-platform

protected JPanel createStatusArea() {
 JPanel statusArea = new JPanel();
 JLabel status =
   new JLabel("No log records to display.");
 _statusLabel = status;
 status.setHorizontalAlignment(JLabel.LEFT);
 statusArea.setBorder(BorderFactory.createEtchedBorder());
 statusArea.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
 statusArea.add(status);
 return (statusArea);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Creates a new <code>DetailPanel</code> instance.
 *
 * @param aTable the table to listen for selections on
 * @param aModel the model backing the table
 */
DetailPanel(JTable aTable, final MyTableModel aModel) {
  mModel = aModel;
  setLayout(new BorderLayout());
  setBorder(BorderFactory.createTitledBorder("Details: "));
  mDetails = new JEditorPane();
  mDetails.setEditable(false);
  mDetails.setContentType("text/html");
  add(new JScrollPane(mDetails), BorderLayout.CENTER);
  final ListSelectionModel rowSM = aTable.getSelectionModel();
  rowSM.addListSelectionListener(this);
}

代码示例来源:origin: stackoverflow.com

l.setBorder(new LineBorder(Color.RED, 2));
return l;
SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    JPanel p = new JPanel(new GridLayout(2,2,4,4));
    p.setBackground(Color.black);
    p.setBorder(new EmptyBorder(4,4,4,4));
    JPanel border = new JPanel(new BorderLayout());
    border.add(getLabel(
      "Border", SwingConstants.CENTER), BorderLayout.CENTER);
    p.add(border);
    JPanel gridbag = new JPanel(new GridBagLayout());
    gridbag.add(getLabel("GridBag"));
    p.add(gridbag);
    p.add(box);
    JFrame f = new JFrame("Streeeetch me..");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(p);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

代码示例来源:origin: stackoverflow.com

private JButton stopButton = new JButton();
private JButton pauseButton = new JButton();
private JPanel mainPanel = new JPanel();
private JProgressBar progressBar = new JProgressBar();
 progressBar.setBorderPainted(true);
 JPanel btnPanel = new JPanel(new GridLayout(1, 0, 5, 0));
 btnPanel.add(playButton);
 btnPanel.add(pauseButton);
 btnPanel.add(stopButton);
 mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
 mainPanel.add(btnPanel, BorderLayout.CENTER);
 mainPanel.add(progressBar, BorderLayout.PAGE_END);

代码示例来源:origin: stackoverflow.com

this.setBorder(BorderFactory.createEmptyBorder(N, N, N, N));
for (int r = 0; r < N; r++) {
  for (int c = 0; c < N; c++) {
    this.add(create(r + N, r + 1, c + 2));
sb.append("</html></body>");
JLabel label = new JLabel(sb.toString(), JLabel.CENTER);
label.setBorder(BorderFactory.createLineBorder(Color.lightGray));
return label;
JFrame f = new JFrame("HTMLFractions");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

代码示例来源:origin: stackoverflow.com

int h = bi.getHeight();
int step = w/3;
JPanel p = new JPanel(new GridLayout(3,3));
p.setOpaque(false);
int count = 0;
      button.setBorder(null);
      p.add(button);
    } else {
      JLabel label = new JLabel(new ImageIcon(icon));
      p.add(label);
JPanel center = new JPanel(new GridBagLayout());
center.setBackground(Color.BLACK);
center.add(p);
JOptionPane.showMessageDialog(null, center);

代码示例来源:origin: stackoverflow.com

Runnable r = new Runnable() {
 public void run() {
  final JFrame f = new JFrame("Test Screenshot");
  f.setJMenuBar(mb);
  JPanel p = new JPanel( new BorderLayout(5,5) );
  p.setBorder( new TitledBorder("Main GUI") );
  p.add( new JScrollPane(new JTree()),
   BorderLayout.WEST );
  p.add( new JScrollPane( new JTextArea(HELP,10,30) ),
   BorderLayout.CENTER );
  f.pack();
  f.setLocationRelativeTo(null);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setVisible(true);

代码示例来源:origin: stackoverflow.com

private JPanel mainPanel = new JPanel();
private SwingPropertyChangeSupport spcSupport = new SwingPropertyChangeSupport(
   this);
 JPanel buttonsPanel = createButtonsPanel();
 mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 mainPanel.setLayout(new BorderLayout(5, 5));
 mainPanel.add(textAreasPanel, BorderLayout.CENTER);
 mainPanel.add(buttonsPanel, BorderLayout.PAGE_END);
 JPanel buttonsPanel = new JPanel(new GridLayout(2, 0, 5, 5));
 for (final GuiButtonText guiBtnText : GuiButtonText.values()) {
   AbstractAction btnAction = new AbstractAction(guiBtnText.getText()) {
   buttonsPanel.add(button);
 JPanel textAreasPanel = new JPanel();
 textAreasPanel.setLayout(new BoxLayout(textAreasPanel,
    BoxLayout.PAGE_AXIS));
   JScrollPane scrollPane = new JScrollPane(tArea);
   JPanel outerPanel = new JPanel(new BorderLayout());
   outerPanel.setBorder(BorderFactory.createTitledBorder(textDest.getText()));
   outerPanel.add(scrollPane);
   textAreasPanel.add(outerPanel);

代码示例来源:origin: stackoverflow.com

this.setBorder(BorderFactory.createTitledBorder("Panel " + n));
GroupLayout layout = new GroupLayout(this);          
this.setLayout(layout);
JFrame f = new JFrame("GroupPanel");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
f.add(new GroupPanel(1));
f.add(new GroupPanel(2));
f.add(Box.createVerticalGlue());
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

代码示例来源:origin: stackoverflow.com

setBorder(standardBorder);
setCursor( new Cursor(Cursor.HAND_CURSOR) );
setBorder(activeBorder);
try {
  Desktop.getDesktop().browse(target);
setBorder(standardBorder);
setBorder(hoverBorder);
setBorder(standardBorder);
setBorder(standardBorder);
setBorder(hoverBorder);
JPanel p = new JPanel(new GridLayout(0,1));
File f = new File(".","LinkLabel.java");
p.add(linkLabelFile);
p.add(linkLabelWeb);
JPanel labelConstrain = new JPanel(new BorderLayout());
labelConstrain.add( linkLabelConstrain, BorderLayout.EAST );
p.add(labelConstrain);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("Input Integer Example");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel contentPane = new JPanel();
contentPane.setBorder(
  BorderFactory.createEmptyBorder(5, 5, 5, 5));
tField = new JTextField(10);
((AbstractDocument)tField.getDocument()).setDocumentFilter(
    new MyDocumentFilter());        
contentPane.add(tField); 
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

l.setBackground(bg);
l.setOpaque(true);
c.add(l);
  l.setBackground(bg);
  l.setOpaque(true);
  c.add(l);
        null, "Use gradient fille color?");
    boolean gradientFill = gradient == JOptionPane.OK_OPTION;
    JPanel gui = new JPanel(new GridLayout(0, 8, 0, 0));
    gui.setBorder(new BevelBorder(
        BevelBorder.LOWERED,
        Color.GRAY.brighter(), Color.GRAY,
        JOptionPane.INFORMATION_MESSAGE);
    JPanel tileSet = new JPanel(new GridLayout(0, 6, 0, 0));
    tileSet.setOpaque(false);
    int[] tileSetOrder = new int[]{

代码示例来源:origin: stackoverflow.com

JPanel contentPane = new JPanel(
        new GridLayout(0, 1, hGap, vGap));
contentPane.setBorder(
  BorderFactory.createEmptyBorder(hGap, vGap, hGap, vGap));
borderPanel = new JPanel(new BorderLayout(hGap, vGap));
borderPanel.setBorder(
  BorderFactory.createTitledBorder("BorderLayout"));
borderPanel.setOpaque(true);
contentPane.add(borderPanel);
flowPanel = new JPanel(new FlowLayout(
      FlowLayout.CENTER, hGap, vGap));
flowPanel.setBorder(
  BorderFactory.createTitledBorder("FlowLayout"));
flowPanel.setOpaque(true);
gridPanel.setBorder(
  BorderFactory.createTitledBorder("GridLayout"));
gridPanel.setOpaque(true);
gridBagPanel.setBorder(
  BorderFactory.createTitledBorder("GridBagLayout"));
gridBagPanel.setOpaque(true);
cardPanel.setBorder(
  BorderFactory.createTitledBorder("CardLayout"));
cardPanel.setOpaque(true);

代码示例来源:origin: org.apache.log4j/com.springsource.org.apache.log4j

protected JPanel createStatusArea() {
 JPanel statusArea = new JPanel();
 JLabel status =
   new JLabel("No log records to display.");
 _statusLabel = status;
 status.setHorizontalAlignment(JLabel.LEFT);
 statusArea.setBorder(BorderFactory.createEtchedBorder());
 statusArea.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
 statusArea.add(status);
 return (statusArea);
}

代码示例来源:origin: stackoverflow.com

tree.expandRow(ii);
  JPanel buttonPanel = new JPanel(buttonLayout);
  gui.add(buttonPanel, BorderLayout.PAGE_START);
  buttonPanel.add(new JLabel("H Gap"));
mainLayout.setVgap(vGap);
buttonLayout.setHgap(hGap);
gui.setBorder(new EmptyBorder(vBorder,hBorder,vBorder,hBorder));
Container c = gui.getTopLevelAncestor();
if (c instanceof Window) {
  Window w = (Window)c;
  w.pack();
    JFrame f = new JFrame("White (OK Red) Space");
    f.add(gui);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.pack();
    f.setVisible(true);

相关文章

JComponent类方法