javax.swing.JLabel.getBorder()方法的使用及代码示例

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

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

JLabel.getBorder介绍

暂无

代码示例

代码示例来源:origin: runelite/runelite

geLimitLabel.setText(limitLabelText);
geLimitLabel.setForeground(ColorScheme.GRAND_EXCHANGE_LIMIT);
geLimitLabel.setBorder(new CompoundBorder(geLimitLabel.getBorder(), new EmptyBorder(0, 0, 0, 7)));
alchAndLimitPanel.add(geLimitLabel, BorderLayout.EAST);

代码示例来源:origin: ron190/jsql-injection

@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
  JLabel labelItemList = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  labelItemList.setBorder(
    BorderFactory.createCompoundBorder(
      BorderFactory.createMatteBorder(3, 3, 0, 3, Color.WHITE),
      labelItemList.getBorder()
    )
  );
  return labelItemList;
}

代码示例来源:origin: magefree/mage

@Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // get table text cell settings
    DefaultTableCellRenderer baseRenderer = (DefaultTableCellRenderer) table.getDefaultRenderer(String.class);
    JLabel baseComp = (JLabel) baseRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    String skillCode = baseComp.getText();
    // apply settings to render panel from parent
    renderPanel.setOpaque(baseComp.isOpaque());
    renderPanel.setForeground(CardRendererUtils.copyColor(baseComp.getForeground()));
    renderPanel.setBackground(CardRendererUtils.copyColor(baseComp.getBackground()));
    renderPanel.setBorder(baseComp.getBorder());
    // create each skill symbol as child label
    renderPanel.removeAll();
    renderPanel.setLayout(new BoxLayout(renderPanel, BoxLayout.X_AXIS));
    for (char skillSymbol : skillCode.toCharArray()) {
      JLabel symbolLabel = new JLabel();
      symbolLabel.setBorder(new EmptyBorder(0, 3, 0, 0));
      symbolLabel.setIcon(skillIcon);
      renderPanel.add(symbolLabel);
    }
    return renderPanel;
  }
};

代码示例来源:origin: magefree/mage

renderPanel.setForeground(CardRendererUtils.copyColor(baseComp.getForeground()));
renderPanel.setBackground(CardRendererUtils.copyColor(baseComp.getBackground()));
renderPanel.setBorder(baseComp.getBorder());

代码示例来源:origin: org.jbundle.util.jcalendarbutton/org.jbundle.util.jcalendarbutton

/**
 * Invoked when the mouse enters a component.
 */
public void mouseEntered(MouseEvent evt)
{
  JLabel button = (JLabel)evt.getSource();
  oldBorder = button.getBorder();
  button.setBorder(ROLLOVER_BORDER);
}
/**

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

public class DefaultLayouts {
  public static JLabel infoLabel(String text) {
    JLabel label = new JLabel(text);

    Border margin = new EmptyBorder(10, 10, 10, 10);
    Border border = label.getBorder();
    label.setBorder(new CompoundBorder(border, margin));

    return label;
  }
}

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

final TableCellRenderer tcrOs = myTable.getTableHeader().getDefaultRenderer();
   myTable.getTableHeader().setDefaultRenderer(new TableCellRenderer() {
     @Override
     public Component getTableCellRendererComponent(JTable table, 
         Object value, boolean isSelected, boolean hasFocus, 
         int row, int column) {
       JLabel lbl = (JLabel) tcrOs.getTableCellRendererComponent(table, 
          value, isSelected, hasFocus, row, column);
       lbl.setForeground(AppVariables.textColor);
       lbl.setBorder(BorderFactory.createCompoundBorder(lbl.getBorder(), 
          BorderFactory.createEmptyBorder(0, 5, 0, 0)));
       lbl.setHorizontalAlignment(SwingConstants.LEFT);
       if (isSelected) {
         lbl.setForeground(Color.red);
         lbl.setBackground(Color.lightGray);
       } else {
         lbl.setForeground(Color.blue);
         lbl.setBackground(Color.black);
       }
       return lbl;
     }
   });

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

static class MyCellRenderer extends JLabel implements ListCellRenderer<Object> {
  public MyCellRenderer() {
    setOpaque(true);
  }

  public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
      boolean cellHasFocus) {
    if (value.getClass().equals(JLabel.class)) {
      JLabel label = JLabel.class.cast(value);
      setIcon(label.getIcon());
      setBorder(label.getBorder());
    }
    return this;
  }
}

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

final TableCellRenderer tcrOs = table.getTableHeader().getDefaultRenderer();
 table.getTableHeader().setDefaultRenderer(new TableCellRenderer() {
   @Override
   public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     JLabel lbl = (JLabel) tcrOs.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     lbl.setBorder(BorderFactory.createCompoundBorder(lbl.getBorder(), BorderFactory.createEmptyBorder(0, 5, 0, 0)));
     lbl.setHorizontalAlignment(SwingConstants.LEFT);
     if (isSelected) {
       lbl.setForeground(Color.red);
       lbl.setFont(new Font("Arial", Font.BOLD, 12));
     } else {
       lbl.setForeground(Color.darkGray);
       lbl.setFont(new Font("Arial", Font.PLAIN, 10));
     }
     return lbl;
   }
 });

代码示例来源:origin: com.google.code.findbugs/findbugs

@Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
      int column) {
    Component comp = defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (comp instanceof JLabel) {
      JLabel cell = (JLabel) comp;
      cell.setFont(cell.getFont().deriveFont(Driver.getFontSize()));
      cell.setFont(cell.getFont().deriveFont(Font.BOLD));
      cell.setBorder(BorderFactory.createCompoundBorder(cell.getBorder(), BorderFactory.createEmptyBorder(0, 6, 0, 6)));
      cell.setHorizontalAlignment(SwingConstants.CENTER);
      if (value == Sortables.DIVIDER) {
        URL arrows = MainFrame.class.getResource("arrows.png");
        if (arrows != null) {
          cell.setText("");
          cell.setIcon(new ImageIcon(arrows));
        } else {
          cell.setText("<->");
        }
      }
    }
    return comp;
  }
}

代码示例来源:origin: com.samskivert/samskivert

public void mousePressed (MouseEvent e)
{
  // ignore if we're not enabled
  if (!isEnabled()) {
    return;
  }
  // keep track of the selected button
  _selectedButton = (JLabel)e.getSource();
  // if the selected button is already selected, ignore the click
  if (_selectedButton.getBorder() == SELECTED_BORDER) {
    _selectedButton = null;
  } else {
    _selectedButton.setBorder(SELECTED_BORDER);
    _selectedButton.repaint();
  }
}

代码示例来源:origin: org.geotools/gt2-widgets-swing

/**
 * Constructs an initially empty parameter editor.
 */
public ParameterEditor() {
  super(new BorderLayout());
  description.setBorder(
      BorderFactory.createCompoundBorder(description.getBorder(),
      BorderFactory.createCompoundBorder(
      BorderFactory.createCompoundBorder(
      BorderFactory.createEmptyBorder(6, 9, 6, 9),
      BorderFactory.createLineBorder(description.getForeground())),
      BorderFactory.createEmptyBorder(6, 0, 6, 0))));
  add(description, BorderLayout.NORTH );
  add(cards,       BorderLayout.CENTER);
  setPreferredSize(new Dimension(400,250));
}

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

JTextArea ta = new JTextArea(text);
 ta.setEditable(false);
 ta.setLineWrap(true);
 ta.setWrapStyleWord(true);
 JLabel lb = new JLabel();
 Font f = lb.getFont();
 ta.setFont(f.deriveFont(f.getSize2D() * 0.9f));
 ta.setBorder(lb.getBorder());
 ta.setBackground(new Color(lb.getBackground().getRGB(), true));
 ta.setForeground(new Color(lb.getForeground().getRGB(), true));
 ta.setOpaque(lb.isOpaque());

代码示例来源:origin: otros-systems/otroslogviewer

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
 String abbreviatePackage = "";
 if (value != null) {
  final ClassWrapper classWrapper = (ClassWrapper) value;
  final String className = Optional.ofNullable(classWrapper.getClassName()).orElse("");
  abbreviatePackage = abbreviatePackageUsingMappings(className, replacements);
  int availableWidth = table.getColumnModel().getColumn(column).getWidth();
  availableWidth -= table.getIntercellSpacing().getWidth();
  if (label.getBorder() != null) {
   Insets borderInsets = label.getBorder().getBorderInsets(label);
   availableWidth -= (borderInsets.left + borderInsets.right);
  }
  FontMetrics fm = label.getFontMetrics(label.getFont());
  abbreviatePackage = abbreviatePackagesToSingleLetter(abbreviatePackage, availableWidth, fm);
  while (fm.stringWidth(abbreviatePackage) > availableWidth && abbreviatePackage.length() > 0) {
   abbreviatePackage = abbreviatePackage.substring(1);
  }
 }
 label.setText(abbreviatePackage);
 return label;
}

代码示例来源:origin: GoldenGnu/jeveassets

@Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    JLabel jLabel = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); //To change body of generated methods, choose Tools | Templates.
    if (value instanceof Tags) {
      Tags tags = (Tags) value;
      JPanel jPanel = tags.getPanel();
      jPanel.setBackground(jLabel.getBackground());
      jPanel.setForeground(jLabel.getForeground());
      jPanel.setBorder(jLabel.getBorder());
      return jPanel;
    }
    return jLabel;
  }
}

代码示例来源:origin: net.java.abeille/abeille

/**
   * Resets the default borders.
   */
  private static void resetDefaultBorders() {
    m_default_borders.clear();
    m_default_borders.put(JButton.class, getDefaultBorder("Button.border"));
    m_default_borders.put(JComboBox.class, getDefaultBorder("ComboBox.border"));
    m_default_borders.put(JLabel.class, new JLabel().getBorder());
    m_default_borders.put(JList.class, getDefaultBorder("List.border"));
    m_default_borders.put(JSpinner.class, getDefaultBorder("Spinner.border"));
    m_default_borders.put(JTable.class, new JTable().getBorder());
    m_default_borders.put(JTextArea.class, getDefaultBorder("TextArea.border"));
    m_default_borders.put(JTextField.class, getDefaultBorder("TextField.border"));
    m_default_borders.put(JTree.class, new JTree().getBorder());
    m_default_borders.put(JScrollPane.class, new JScrollPane().getBorder());

    m_default_borders.put(JCheckBox.class, new javax.swing.border.EmptyBorder(1, 0, 1, 2));
    m_default_borders.put(JRadioButton.class, new javax.swing.border.EmptyBorder(1, 0, 1, 2));

    /**
     * JCheckBox and JRadioButton have overriden borders because their
     * default borders have a horizontal offset that produces a rather
     * unpleasant looking GUI.
     */
  }
}

代码示例来源:origin: AndreasFagschlunger/O2Xfs

@Override
public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
  final Component template = super.getTableCellRendererComponent(table,
      value, isSelected, hasFocus, row, column);
  textArea.setForeground(template.getForeground());
  textArea.setBackground(template.getBackground());
  textArea.setBorder(((JLabel) template).getBorder());
  textArea.setText(String.valueOf(value));
  final TableColumn tableColumn = table.getColumnModel()
      .getColumn(column);
  final View view = textArea.getUI().getRootView(textArea);
  view.setSize(tableColumn.getWidth(), 0);
  final int rowHeight = (int) view.getPreferredSpan(View.Y_AXIS)
      + (table.getIntercellSpacing().height * 2);
  if (table.getRowHeight(row) != rowHeight) {
    table.setRowHeight(row, rowHeight);
  }
  return textArea;
}

代码示例来源:origin: violetumleditor/violetumleditor

protected LineText(LineText lineText) throws CloneNotSupportedException
{
  getLabel().setHorizontalAlignment(lineText.getLabel().getHorizontalAlignment());
  getLabel().setVerticalAlignment(lineText.getLabel().getVerticalAlignment());
  getLabel().setForeground(lineText.getLabel().getForeground());
  getLabel().setBorder(lineText.getLabel().getBorder());
  getLabel().setText(lineText.getLabel().getText());
  converter = lineText.converter;
}

代码示例来源:origin: chatty/chatty

public WrapLabel() {
  setWrapStyleWord(true);
  setLineWrap(true);
  setBackground(LABEL.getBackground());
  setFont(LABEL.getFont());
  setBorder(LABEL.getBorder());
  setFocusable(false);
  setForeground(LABEL.getForeground());
  setOpaque(false);
  System.out.println(getColumns());
  setRows(1);
  setColumns(20);
}

代码示例来源:origin: org.trypticon.hex/hex-util

private void updateProperties() {
  labelTemplate.putClientProperty("JComponent.sizeVariant", getClientProperty("JComponent.sizeVariant"));
  textFieldTemplate.putClientProperty("JComponent.sizeVariant", getClientProperty("JComponent.sizeVariant"));
  // Make the label insets the same as the text field to stop the UI jumping around every time the state changes.
  Insets insets = textFieldTemplate.getBorder().getBorderInsets(this);
  labelTemplate.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
  setFont(labelTemplate.getFont());
  if (hasFocus()) {
    textFieldTemplate.setEditable(isEditable());
    setOpaque(true);
    setBorder(textFieldTemplate.getBorder());
    setForeground(textFieldTemplate.getForeground());
    setBackground(textFieldTemplate.getBackground());
  } else {
    setOpaque(false);
    setBorder(labelTemplate.getBorder());
    setForeground(labelTemplate.getForeground());
    setBackground(TRANSPARENT);
  }
}

相关文章

JLabel类方法