javax.swing.JTextField.setLayout()方法的使用及代码示例

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

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

JTextField.setLayout介绍

暂无

代码示例

代码示例来源:origin: org.scijava/scijava-ui-swing

private void initPrompt(String text) {
  prompt.setText(text);
  prompt.setFont(textField.getFont().deriveFont(Font.ITALIC));
  prompt.setForeground(changeAlpha(textField.getForeground(), 128));
  prompt.setBorder(new EmptyBorder(textField.getInsets()));
  prompt.setHorizontalAlignment(SwingConstants.LEADING);
  textField.setLayout(new BorderLayout());
  textField.add(prompt);
  updatePromptVisibility();
}

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

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField textField = new JTextField("Search...");
textField.setLayout(new BorderLayout());

代码示例来源:origin: org.metawidget.modules/metawidget-all

public void startContainerLayout( JComponent container, SwingMetawidget metawidget ) {
  container.putClientProperty( GridBagLayout.class, null );
  State state = getState( container );
  // Calculate default label inset
  //
  // We top align all our labels, not just those belonging to 'tall' components,
  // so that tall components, regular components and nested Metawidget components all line up.
  // However, we still want the JLabels to be middle aligned for one-line components (such as
  // JTextFields), so we top inset them a bit
  java.awt.GridBagLayout layoutManager = new java.awt.GridBagLayout();
  container.setLayout( layoutManager );
  JTextField dummyTextField = new JTextField();
  dummyTextField.setLayout( layoutManager );
  double dummyTextFieldHeight = dummyTextField.getPreferredSize().getHeight();
  JLabel dummyLabel = new JLabel( "X" );
  dummyLabel.setLayout( layoutManager );
  double dummyLabelHeight = dummyLabel.getPreferredSize().getHeight();
  int defaultLabelVerticalPadding = (int) Math.max( 0, Math.floor( ( dummyTextFieldHeight - dummyLabelHeight ) / 2 ) );
  state.defaultLabelInsetsFirstColumn = new Insets( defaultLabelVerticalPadding, 0, defaultLabelVerticalPadding, SMALL_GAP );
  state.defaultLabelInsetsRemainderColumns = new Insets( defaultLabelVerticalPadding, SMALL_GAP, defaultLabelVerticalPadding, SMALL_GAP );
}

代码示例来源:origin: org.metawidget.modules.swing/metawidget-swing

public void startContainerLayout( JComponent container, SwingMetawidget metawidget ) {
  container.putClientProperty( GridBagLayout.class, null );
  State state = getState( container );
  // Calculate default label inset
  //
  // We top align all our labels, not just those belonging to 'tall' components,
  // so that tall components, regular components and nested Metawidget components all line up.
  // However, we still want the JLabels to be middle aligned for one-line components (such as
  // JTextFields), so we top inset them a bit
  java.awt.GridBagLayout layoutManager = new java.awt.GridBagLayout();
  container.setLayout( layoutManager );
  JTextField dummyTextField = new JTextField();
  dummyTextField.setLayout( layoutManager );
  double dummyTextFieldHeight = dummyTextField.getPreferredSize().getHeight();
  JLabel dummyLabel = new JLabel( "X" );
  dummyLabel.setLayout( layoutManager );
  double dummyLabelHeight = dummyLabel.getPreferredSize().getHeight();
  int defaultLabelVerticalPadding = (int) Math.max( 0, Math.floor( ( dummyTextFieldHeight - dummyLabelHeight ) / 2 ) );
  state.defaultLabelInsetsFirstColumn = new Insets( defaultLabelVerticalPadding, 0, defaultLabelVerticalPadding, SMALL_GAP );
  state.defaultLabelInsetsRemainderColumns = new Insets( defaultLabelVerticalPadding, SMALL_GAP, defaultLabelVerticalPadding, SMALL_GAP );
}

代码示例来源:origin: IanDarwin/javasrc

public TextFieldWithClearButton() {
  final JTextField tf = new JTextField(15);
  tf.setLayout(new FlowLayout(FlowLayout.RIGHT));
  final Dimension d = tf.getPreferredSize();
  d.height *= 2;
  tf.setPreferredSize(d);
  JButton b1 = new JButton("X");
  tf.add(b1);
  b1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {
      tf.setText("");
    }
  });
  final JPanel p = new JPanel();
  p.setBorder(BorderFactory.createTitledBorder("Scram"));
  p.add(tf);
  setContentPane(p);
  //setSize(200, 60);
  pack();
}

代码示例来源:origin: org.apache.uima/uimaj-tools

pearFileTextField.setBounds(83, 40, 492, 20);
pearFileTextField.setLayout(new BorderLayout());
pearFileTextField.addActionListener(new java.awt.event.ActionListener() {
 @Override

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

/**
 * Installs a {@link BuddyLayoutAndBorder} as a layout and border of the
 * given text field. Registers a {@link PropertyChangeListener} to wrap any
 * subsequently set border on the text field.
 */
protected void install(JTextField textField) {
  uninstall();
  this.textField = textField;
  textField.setLayout(this);
  replaceBorderIfNecessary();
  textField.addPropertyChangeListener("border", this);
}

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

public void uninstall() {
  if (textField != null) {
    textField.removePropertyChangeListener("border", this);
    if (textField.getBorder() == this) {
      textField.setBorder(borderDelegate);
    }
    textField.setLayout(null);
    textField = null;
  }
}

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

public void uninstall() {
  if (textField != null) {
    textField.removePropertyChangeListener("border", this);
    if (textField.getBorder() == this) {
      textField.setBorder(borderDelegate);
    }
    textField.setLayout(null);
    textField = null;
  }
}

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

/**
 * Installs a {@link BuddyLayoutAndBorder} as a layout and border of the
 * given text field. Registers a {@link PropertyChangeListener} to wrap any
 * subsequently set border on the text field.
 */
protected void install(JTextField textField) {
  uninstall();
  this.textField = textField;
  textField.setLayout(this);
  replaceBorderIfNecessary();
  textField.addPropertyChangeListener("border", this);
}

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

public void uninstall() {
  if (textField != null) {
    textField.removePropertyChangeListener("border", this);
    if (textField.getBorder() == this) {
      textField.setBorder(borderDelegate);
    }
    textField.setLayout(null);
    textField = null;
  }
}

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

/**
 * Installs a {@link BuddyLayoutAndBorder} as a layout and border of the
 * given text field. Registers a {@link PropertyChangeListener} to wrap any
 * subsequently set border on the text field.
 */
protected void install(JTextField textField) {
  uninstall();
  this.textField = textField;
  textField.setLayout(this);
  replaceBorderIfNecessary();
  textField.addPropertyChangeListener("border", this);
}

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

/**
 * Installs a {@link BuddyLayoutAndBorder} as a layout and border of the
 * given text field. Registers a {@link PropertyChangeListener} to wrap any
 * subsequently set border on the text field.
 */
protected void install(JTextField textField) {
  uninstall();
  this.textField = textField;
  textField.setLayout(this);
  replaceBorderIfNecessary();
  textField.addPropertyChangeListener("border", this);
}

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

public void uninstall() {
  if (textField != null) {
    textField.removePropertyChangeListener("border", this);
    if (textField.getBorder() == this) {
      textField.setBorder(borderDelegate);
    }
    textField.setLayout(null);
    textField = null;
  }
}

代码示例来源:origin: IanDarwin/darwinsys-api

/** Construct the Search Box including its GUI.
 * @param borderStr The border title; if null, no titled border added
 */
public SearchBox(String borderStr) {
  super();
  setLayout(new FlowLayout()); // default
  
  if (borderStr != null) {
    this.setBorder(BorderFactory.createTitledBorder(borderStr));
  }
  add(text = new JTextField(10));
  clearButton = new JButton("X");
  if (imbed ) {
    text.setLayout(new FlowLayout(FlowLayout.RIGHT));
    Dimension d = text.getPreferredSize();
    d.height *= 1.7;
    text.setPreferredSize(d);
    final Font xFont = clearButton.getFont();
    Font newFont = xFont.deriveFont(xFont.getSize2D()*0.7f);
    clearButton.setFont(newFont);
    text.add(clearButton);
  } else {
    // Plain mode, add it beside the textfield
    add(clearButton);
  }
  clearButton.addActionListener(clearer);
}

代码示例来源:origin: org.metawidget.modules/metawidget-all

dummyTextField.setLayout( layoutManager );
double dummyTextFieldHeight = dummyTextField.getPreferredSize().getHeight();

代码示例来源:origin: com.darwinsys/darwinsys-api

/** Construct the Search Box including its GUI.
 * @param borderStr The border title; if null, no titled border added
 */
public SearchBox(String borderStr) {
  super();
  setLayout(new FlowLayout()); // default
  
  if (borderStr != null) {
    this.setBorder(BorderFactory.createTitledBorder(borderStr));
  }
  add(text = new JTextField(10));
  clearButton = new JButton("X");
  if (imbed ) {
    text.setLayout(new FlowLayout(FlowLayout.RIGHT));
    Dimension d = text.getPreferredSize();
    d.height *= 1.7;
    text.setPreferredSize(d);
    final Font xFont = clearButton.getFont();
    Font newFont = xFont.deriveFont(xFont.getSize2D()*0.7f);
    clearButton.setFont(newFont);
    text.add(clearButton);
  } else {
    // Plain mode, add it beside the textfield
    add(clearButton);
  }
  clearButton.addActionListener(clearer);
}

相关文章

微信公众号

最新文章

更多

JTextField类方法