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

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

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

JTextComponent.getPreferredSize介绍

暂无

代码示例

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

public boolean getScrollableTracksViewportWidth()
{
 return getParent().getWidth() > _editor.getPreferredSize().width;
}

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

public boolean getScrollableTracksViewportWidth()
{
 return getParent().getWidth() > _editor.getPreferredSize().width;
}

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

private void documentChanged() {
  //  Preferred size of the component has not been updated at the time
  //  the DocumentEvent is fired
  SwingUtilities.invokeLater(() -> {
    int preferredHeight = component.getPreferredSize().height;
    //  Document change has caused a change in the number of lines.
    //  Repaint to reflect the new line numbers
    if (lastHeight != preferredHeight) {
      setPreferredWidth();
      repaint();
      lastHeight = preferredHeight;
    }
  });
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-designer

private static Dimension computeSizeForTextComponentColumns(JTextComponent textComponent, int columns) {
    Dimension size = textComponent.getPreferredSize();
    Font font = textComponent.getFont();
    if (font == null) {
      return size;
    }
    FontMetrics fontMetrics = textComponent.getFontMetrics(font);
    if (fontMetrics == null) {
      return size;
    }
//        Insets insets = textComponent.getInsets();
//        int insetsWidth = insets == null ? 0 : insets.left + insets.right;
    size.width = columns * (fontMetrics.charWidth('a'))/* + insetsWidth*/; // NOI18N
    return size;
  }

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

public boolean getScrollableTracksViewportHeight()
 {
  return getParent().getHeight() > _editor.getPreferredSize().height;
 }
}

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

public boolean getScrollableTracksViewportHeight()
 {
  return getParent().getHeight() > _editor.getPreferredSize().height;
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

public Dimension getPreferredSize() {
  if (isVisible()) {
    return new Dimension(getInsets().left + ICON_WIDTH + getInsets().right, editor.getPreferredSize().height);
  }
  return null;
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

public Dimension getMinimumSize() {
  if (isVisible()) {
    return new Dimension(getInsets().left + ICON_WIDTH + getInsets().right, editor.getPreferredSize().height);
  }
  return null;
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

public Dimension getMaximumSize() {
  if (isVisible()) {
    return new Dimension(getInsets().left + ICON_WIDTH + getInsets().right, editor.getPreferredSize().height);
  }
  return null;
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

/**
 * @return the maximum dimension.
 */
public Dimension getMaximumSize() {
  if (isVisible()) {
    return new Dimension(getInsets().left + getMarginwidth() + getInsets().right, editor.getPreferredSize().height);		
  }
  
  return null;
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

/**
 * @return the minimum dimension.
 */
public Dimension getMinimumSize() {
  if (isVisible()) {
    return new Dimension(getInsets().left + getMarginwidth() + getInsets().right, editor.getPreferredSize().height);		
  }
  
  return null;
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

/**
 * @return the preferred dimension.
 */
public Dimension getPreferredSize() {
  if (isVisible()) {
    return new Dimension(getInsets().left + getMarginwidth() + getInsets().right, editor.getPreferredSize().height);		
  }
  
  return null;
}

代码示例来源:origin: net.sf.squirrel-sql/squirrel-sql

public FindInObjectTreePanel(JTextComponent textComponent, SquirrelResources resources)
  {
   setLayout(new GridBagLayout());
   GridBagConstraints gbc;

   gbc = new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,0), 0,0);
   add(textComponent, gbc);

   gbc = new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2,0,2,0), 0,0);
   _btnFind = new JButton(resources.getIcon(SquirrelResources.IImageNames.FIND));
   _btnFind.setBorder(BorderFactory.createEtchedBorder());
   _btnFind.setToolTipText(s_stringMgr.getString("FindInObjectTreePanel.find"));
   add(_btnFind, gbc);

   gbc = new GridBagConstraints(2,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2,0,2,2), 0,0);
   _btnApplyAsFilter = new JToggleButton(resources.getIcon(SquirrelResources.IImageNames.FILTER));
   _btnApplyAsFilter.setBorder(BorderFactory.createEtchedBorder());
   _btnApplyAsFilter.setToolTipText(s_stringMgr.getString("FindInObjectTreePanel.applyAsFilter"));
   add(_btnApplyAsFilter, gbc);

   Dimension preferredSize = textComponent.getPreferredSize();
   preferredSize.height = _btnFind.getPreferredSize().height;
   textComponent.setPreferredSize(preferredSize);

   textComponent.setBorder(BorderFactory.createEtchedBorder());

  }
}

代码示例来源:origin: com.haulmont.thirdparty/swingx-core

/**
 * When {@link #shouldPaintPrompt(JTextComponent)} returns true, the prompt
 * component is retrieved by calling
 * {@link #getPromptComponent(JTextComponent)} and it's preferred size is
 * returned. Otherwise super{@link #getPreferredSize(JComponent)} is called.
 */
@Override
public Dimension getPreferredSize(JComponent c) {
  JTextComponent txt = (JTextComponent) c;
  if (shouldPaintPrompt(txt)) {
    return getPromptComponent(txt).getPreferredSize();
  }
  return delegate.getPreferredSize(c);
}

代码示例来源:origin: org.swinglabs.swingx/swingx-all

/**
 * When {@link #shouldPaintPrompt(JTextComponent)} returns true, the prompt
 * component is retrieved by calling
 * {@link #getPromptComponent(JTextComponent)} and it's preferred size is
 * returned. Otherwise super{@link #getPreferredSize(JComponent)} is called.
 */
@Override
public Dimension getPreferredSize(JComponent c) {
  JTextComponent txt = (JTextComponent) c;
  if (shouldPaintPrompt(txt)) {
    return getPromptComponent(txt).getPreferredSize();
  }
  return delegate.getPreferredSize(c);
}

代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core

/**
 * When {@link #shouldPaintPrompt(JTextComponent)} returns true, the prompt
 * component is retrieved by calling
 * {@link #getPromptComponent(JTextComponent)} and it's preferred size is
 * returned. Otherwise super{@link #getPreferredSize(JComponent)} is called.
 */
@Override
public Dimension getPreferredSize(JComponent c) {
  JTextComponent txt = (JTextComponent) c;
  if (shouldPaintPrompt(txt)) {
    return getPromptComponent(txt).getPreferredSize();
  }
  return delegate.getPreferredSize(c);
}

代码示例来源:origin: realXuJiang/bigtable-sql

public FindInObjectTreePanel(JTextComponent textComponent, SquirrelResources resources)
  {
   setLayout(new GridBagLayout());
   GridBagConstraints gbc;

   gbc = new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,0), 0,0);
   add(textComponent, gbc);

   gbc = new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2,0,2,0), 0,0);
   _btnFind = new JButton(resources.getIcon(SquirrelResources.IImageNames.FIND));
   _btnFind.setBorder(BorderFactory.createEtchedBorder());
   _btnFind.setToolTipText(s_stringMgr.getString("FindInObjectTreePanel.find"));
   add(_btnFind, gbc);

   gbc = new GridBagConstraints(2,0,1,1,0,0,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2,0,2,2), 0,0);
   _btnApplyAsFilter = new JToggleButton(resources.getIcon(SquirrelResources.IImageNames.FILTER));
   _btnApplyAsFilter.setBorder(BorderFactory.createEtchedBorder());
   _btnApplyAsFilter.setToolTipText(s_stringMgr.getString("FindInObjectTreePanel.applyAsFilter"));
   add(_btnApplyAsFilter, gbc);

   Dimension preferredSize = textComponent.getPreferredSize();
   preferredSize.height = _btnFind.getPreferredSize().height;
   textComponent.setPreferredSize(preferredSize);

   textComponent.setBorder(BorderFactory.createEtchedBorder());

  }
}

代码示例来源:origin: org.swinglabs.swingx/swingx-core

/**
 * When {@link #shouldPaintPrompt(JTextComponent)} returns true, the prompt
 * component is retrieved by calling
 * {@link #getPromptComponent(JTextComponent)} and it's preferred size is
 * returned. Otherwise super{@link #getPreferredSize(JComponent)} is called.
 */
@Override
public Dimension getPreferredSize(JComponent c) {
  JTextComponent txt = (JTextComponent) c;
  if (shouldPaintPrompt(txt)) {
    return getPromptComponent(txt).getPreferredSize();
  }
  return delegate.getPreferredSize(c);
}

代码示例来源:origin: bcdev/beam

private void setTextComponent(JTextComponent textComponent) {
  if (_textComponent != null) {
    _textComponent.removeFocusListener(_focusListener);
    _focusListener = null;
  }
  _textComponent = textComponent;
  if (_textComponent != null) {
    _focusListener = createFocusListener();
    _textComponent.addFocusListener(_focusListener);
  }
  if (_textComponent instanceof JTextArea) {
    _textComponent.setBorder(null);
    final JScrollPane pane = new JScrollPane(_textComponent);
    nameComponent(_component, "ScrollPane");
    pane.setMinimumSize(_textComponent.getPreferredSize());
    _component = pane;
  } else {
    _component = _textComponent;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-designer

private static Dimension computeSizeForTextComponent(JTextComponent textComponent) {
  if (textComponent instanceof JTextField) {
    JTextField textField = (JTextField)textComponent;
    int columns = textField.getColumns();
    if (columns > 0) {
      return computeSizeForTextComponentColumns(textComponent, columns);
    }
  } else if (textComponent instanceof JTextArea) {
    JTextArea textArea = (JTextArea)textComponent;
    int columns = textArea.getColumns();
    if (columns > 0) {
      return computeSizeForTextComponentColumns(textComponent, columns);
    }
  }
  return textComponent.getPreferredSize();
}

相关文章

JTextComponent类方法