javax.swing.text.JTextComponent.getInsets()方法的使用及代码示例

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

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

JTextComponent.getInsets介绍

暂无

代码示例

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

default void drawPlaceholder(JTextComponent textComponent, Graphics g, String placeholderText) {
  int w = textComponent.getWidth();
  
  ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  
  Insets ins = textComponent.getInsets();
  FontMetrics fm = g.getFontMetrics();
  
  int c0 = textComponent.getBackground().getRGB();
  int c1 = textComponent.getForeground().getRGB();
  int m = 0xfefefefe;
  int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1);
  
  g.setColor(new Color(c2, true));
  g.setFont(textComponent.getFont().deriveFont(Font.ITALIC));
  
  g.drawString(
    placeholderText,
    textComponent.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT
      ? w - (fm.stringWidth(placeholderText) + ins.left + 2)
      : ins.left + 2,
    fm.getAscent() + 2
  );
}

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

private void updateRowHeights() {
  final TableColumnModel columnModel = textTable.getColumnModel();
  Insets i=null;
  for(int row = 0; row < textTable.getRowCount(); row++) {
    int rowHeight = textTable.getRowHeight();
    for(int column = 0; column < textTable.getColumnCount(); column++) {
      Component comp = textTable.prepareRenderer(
        textTable.getCellRenderer(row, column), row, column);
      final int height;
      if(comp instanceof JTextComponent) {
        final JTextComponent tc = (JTextComponent)comp;
        final View rootView = tc.getUI().getRootView(tc);
        i=tc.getInsets(null);
        rootView.setSize(columnModel.getColumn(column)
          .getPreferredWidth()-i.left-i.right,
          Integer.MAX_VALUE);
        height=(int)rootView.getPreferredSpan(View.Y_AXIS);
      }
      else height = comp.getPreferredSize().height;
      rowHeight = Math.max(rowHeight, height);
    }
    textTable.setRowHeight(row, rowHeight);
  }
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-editor

@Override
public void paintComponent( Graphics g )
{
 super.paintComponent( g );
 g.setColor( editor.util.EditorUtilities.CONTROL_SHADOW );
 g.setFont( _editor.getFont() );
 FontMetrics fm = g.getFontMetrics( _editor.getFont() );
 int iLineHeight = fm.getHeight();
 int iMargin = _editor.getInsets().top;
 int iLines = getHeight() / iLineHeight;
 for( int i = 1; i <= iLines; i++ )
 {
  String strLine = String.valueOf( i );
  int iWidth = fm.stringWidth( strLine );
  g.drawString( strLine, getWidth() - iWidth - getLineInfoRequiredWidth(), i * iLineHeight - fm.getDescent() + iMargin );
  renderLineInfo( g, i, iLineHeight, getWidth() - getLineInfoRequiredWidth(), (i - 1) * iLineHeight + iMargin );
 }
}

代码示例来源:origin: atarw/material-ui-swing

@Override
public void paintSafely (Graphics g) {
  JPasswordField c = (JPasswordField) getComponent ();
  g = MaterialDrawingUtils.getAliasedGraphics (g);
  if (getComponent ().hasFocus ()) {
    c.setBackground (focusedBackground);
    c.setSelectionColor (focusedSelectionBackground);
  }
  else {
    c.setBackground (unfocusedBackground);
    c.setSelectionColor (unfocusedSelectionBackground);
  }
  int x = getComponent ().getInsets ().left;
  int y = getComponent ().getInsets ().top;
  int w = getComponent ().getWidth () - getComponent ().getInsets ().left - getComponent ().getInsets ().right;
  g.setColor (c.getBackground ());
  g.fillRect (x, c.getHeight () - y, w, 2);
  super.paintSafely (g);
}

代码示例来源:origin: SKCraft/SKMCLauncher

public TextPrompt(String text, JTextComponent component, Show show) {
  this.component = component;
  setShow(show);
  document = component.getDocument();
  setText(text);
  setFont(component.getFont());
  setForeground(component.getForeground());
  setBorder(new EmptyBorder(component.getInsets()));
  setHorizontalAlignment(JLabel.LEADING);
  component.addFocusListener(this);
  document.addDocumentListener(this);
  component.setLayout(new BorderLayout());
  component.add(this);
  checkForPrompt();
}

代码示例来源:origin: semuxproject/semux-core

public TextPrompt(String text, JTextComponent component, Show show) {
  this.component = component;
  setShow(show);
  document = component.getDocument();
  setText(text);
  setFont(component.getFont());
  setForeground(component.getForeground());
  setBorder(new EmptyBorder(component.getInsets()));
  setHorizontalAlignment(JLabel.LEADING);
  component.addFocusListener(this);
  document.addDocumentListener(this);
  component.setLayout(new BorderLayout());
  component.add(this);
  checkForPrompt();
}

代码示例来源:origin: net.java.dev.swing-layout/swing-layout

/**
 * Returns the baseline for single line text components, like
 * <code>JTextField</code>.
 */
private static int getSingleLineTextBaseline(JTextComponent textComponent,
                       int h) {
  View rootView = textComponent.getUI().getRootView(textComponent);
  if (rootView.getViewCount() > 0) {
    Insets insets = textComponent.getInsets();
    int height = h - insets.top - insets.bottom;
    int y = insets.top;
    View fieldView = rootView.getView(0);
  int vspan = (int)fieldView.getPreferredSpan(View.Y_AXIS);
  if (height != vspan) {
  int slop = height - vspan;
  y += slop / 2;
  }
    FontMetrics fm = textComponent.getFontMetrics(
               textComponent.getFont());
    y += fm.getAscent();
    return y;
  }
  return -1;
}

代码示例来源:origin: net.java.dev.swing-layout/swing-layout

/**
 * Returns the baseline for single line text components, like
 * <code>JTextField</code>.
 */
private int getSingleLineTextBaseline(JTextComponent textComponent,
                       int h) {
  View rootView = textComponent.getUI().getRootView(textComponent);
  if (rootView.getViewCount() > 0) {
    Insets insets = textComponent.getInsets();
    int height = h - insets.top - insets.bottom;
    int y = insets.top;
    View fieldView = rootView.getView(0);
  int vspan = (int)fieldView.getPreferredSpan(View.Y_AXIS);
  if (height != vspan) {
  int slop = height - vspan;
  y += slop / 2;
  }
    FontMetrics fm = textComponent.getFontMetrics(
               textComponent.getFont());
    y += fm.getAscent();
    return y;
  }
  return -1;
}

相关文章

JTextComponent类方法