本文整理了Java中javax.swing.JTextField.getPreferredSize()
方法的一些代码示例,展示了JTextField.getPreferredSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.getPreferredSize()
方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:getPreferredSize
暂无
代码示例来源:origin: libgdx/libgdx
mavenTextField = new JTextField(15);
mavenTextField.setMinimumSize(mavenTextField.getPreferredSize());
mavenLabel.setForeground(new Color(170, 170, 170));
mavenDesc.setForeground(new Color(170, 170, 170));
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(new JLabel("Name:"));
nameField = new JTextField(System.getProperty("user.name", "yourname"));
Dimension d = nameField.getPreferredSize();
nameField.setMaximumSize(new Dimension(120, d.height + 6));
p.add(nameField);
p.add(new JLabel(" Message:"));
messageField = new JTextField();
p.add(messageField);
p.add(new JButton(new SendAction(true)));
代码示例来源:origin: stackoverflow.com
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
JTextField field = new JTextField("test");
Dimension d = field.getPreferredSize();
field.setBounds(e.getX(), e.getY(), d.width, d.height);
add(field);
代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui
public static int getDefaultSpinnerHeight() {
if (defaultSpinnerHeight == -1) {
defaultSpinnerHeight = new JTextField().getPreferredSize().height;
}
return defaultSpinnerHeight;
}
代码示例来源:origin: freeplane/freeplane
public void adjustWidthToMaximumValue() {
final JTextField testTextField = new JTextField(Integer.toString(max));
final int width = testTextField.getPreferredSize().width;
final int height = testTextField.getPreferredSize().height;
textField.setPreferredSize(new Dimension(width, height));
textField.revalidate();
}
代码示例来源:origin: openmicroscopy/bioformats
public static JTextField makeTextField() {
JTextField textField = new JTextField(48);
int prefHeight = textField.getPreferredSize().height;
textField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prefHeight));
textField.setEditable(false);
return textField;
}
代码示例来源:origin: ome/bio-formats_plugins
public static JTextField makeTextField() {
JTextField textField = new JTextField(48);
int prefHeight = textField.getPreferredSize().height;
textField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prefHeight));
textField.setEditable(false);
return textField;
}
代码示例来源:origin: bcdev/beam
@Override
public Dimension getPreferredSize() {
Runtime.getRuntime().maxMemory();
Dimension size1 = getXEditorButton().getPreferredSize();
Dimension size2 = new JTextField(1).getPreferredSize();
int height = Math.max(size1.height, size2.height);
return new Dimension(3 * height, height);
}
代码示例来源:origin: stackoverflow.com
menuBar.add(Box.createHorizontalGlue());
JTextField textField = new JTextField(10);
textField.setMaximumSize( textField.getPreferredSize() );
menuBar.add(textField);
代码示例来源:origin: stackoverflow.com
JTextField tf = new JTextField(10);
Dimension d = tf.getPreferredSize();
tf.setBounds(x, y, d.width, d.height);
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_tcp
private JPanel createEolBytePanel() {
JLabel label = new JLabel(JMeterUtils.getResString("eolbyte")); //$NON-NLS-1$
eolByte = new JTextField(3); // 3 columns size
eolByte.setMaximumSize(new Dimension(eolByte.getPreferredSize()));
label.setLabelFor(eolByte);
JPanel eolBytePanel = new JPanel(new FlowLayout());
eolBytePanel.add(label);
eolBytePanel.add(eolByte);
return eolBytePanel;
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_tcp
private JPanel createSoLingerOption() {
JLabel label = new JLabel(JMeterUtils.getResString("solinger")); //$NON-NLS-1$
soLinger = new JTextField(5); // 5 columns size
soLinger.setMaximumSize(new Dimension(soLinger.getPreferredSize()));
label.setLabelFor(soLinger);
JPanel soLingerPanel = new JPanel(new FlowLayout());
soLingerPanel.add(label);
soLingerPanel.add(soLinger);
return soLingerPanel;
}
代码示例来源:origin: stackoverflow.com
JTextField txt = new JTextField(10); // we add a new button
//txt.setPreferredSize(dim); // don't hardcode a preferrd size of a component.
txt.setMaximumSize(txt.getPreferredSize());
代码示例来源:origin: com.synaptix/SynaptixWidget
public AbstractTextFieldFilter(String id, String name, int width, boolean useDefault, String defaultValue) {
super();
this.id = id;
this.name = name;
textField = new JTextField();
textField.setPreferredSize(new Dimension(width, textField.getPreferredSize().height));
textField.getDocument().addDocumentListener(new MyDocumentListener());
if (useDefault) {
defaultTextField = new JTextField();
defaultTextField.setPreferredSize(new Dimension(width, defaultTextField.getPreferredSize().height));
setDefaultValue(defaultValue);
}
initialize();
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-midp
private void initComponents() {
setLayout(new GridBagLayout());
textField = new JTextField();
textField.getDocument().addDocumentListener(this);
textField.addFocusListener(this);
textField.setPreferredSize(new Dimension(100, textField.getPreferredSize().height));
add(textField, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
foreverCheckBox = new JCheckBox();
Mnemonics.setLocalizedText(foreverCheckBox, NbBundle.getMessage(PropertyEditorGaugeMaxValue.class, "LBL_MAX_VALUE_INDEFINITE")); // NOI18N
foreverCheckBox.addActionListener(this);
foreverCheckBox.addFocusListener(this);
add(foreverCheckBox, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
add(new JPanel(), new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core
/**
* Create a GUI panel containing the components related to the number of
* seconds which should be executed.
*
* @return a GUI panel containing the loop count components
*/
private JPanel createLoopCountPanel() {
JPanel loopPanel = new JPanel(new BorderLayout(5, 0));
// SECONDS LABEL
JLabel secondsLabel = new JLabel(JMeterUtils.getResString("runtime_seconds")); // $NON-NLS-1$
loopPanel.add(secondsLabel, BorderLayout.WEST);
JPanel loopSubPanel = new JPanel(new BorderLayout(5, 0));
// TEXT FIELD
seconds = new JTextField("1", 5); // $NON-NLS-1$
secondsLabel.setLabelFor(seconds);
loopSubPanel.add(seconds, BorderLayout.CENTER);
loopPanel.add(loopSubPanel, BorderLayout.CENTER);
loopPanel.add(Box.createHorizontalStrut(secondsLabel.getPreferredSize().width
+ seconds.getPreferredSize().width), BorderLayout.NORTH);
return loopPanel;
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_components
/**
* Create a GUI panel containing the lockName
*
* @return a GUI panel containing the lock name components
*/
private JPanel createCriticalSectionPanel() {
JPanel conditionPanel = new JPanel(new BorderLayout(5, 0));
// Condition LABEL
JLabel conditionLabel = new JLabel(
JMeterUtils.getResString("critical_section_controller_label")); // $NON-NLS-1$
conditionPanel.add(conditionLabel, BorderLayout.WEST);
// TEXT FIELD
tfLockName = new JTextField(""); // $NON-NLS-1$
conditionLabel.setLabelFor(tfLockName);
conditionPanel.add(tfLockName, BorderLayout.CENTER);
conditionPanel
.add(Box.createHorizontalStrut(conditionLabel
.getPreferredSize().width
+ tfLockName.getPreferredSize().width),
BorderLayout.NORTH);
return conditionPanel;
}
}
代码示例来源:origin: igvteam/igv
private void initContentPanel(java.util.List<String> labels) {
textComponents = new HashMap<String, JTextField>(labels.size());
contentPanel.setLayout(new GridLayout(labels.size(), 2, 5, 5));
int width = 0;
int height = 0;
for (String l : labels) {
JTextField field = new JTextField();
textComponents.put(l, field);
final JLabel jlabel = new JLabel(l);
contentPanel.add(jlabel);
contentPanel.add(field);
Dimension d = jlabel.getPreferredSize();
width = Math.max(width, (int) d.getWidth());
double h2 = (int) field.getPreferredSize().getHeight();
height += (int) Math.max(h2, d.getHeight()) + 5;
}
// Why is setting size explicitly neccessary?
width = width*2 + 20;
height += 20;
contentPanel.setSize(width, height);
contentPanel.setPreferredSize(new Dimension(width, height));
pack();
}
代码示例来源:origin: stackoverflow.com
JTextField textField = new JTextField(2);
textField.setSize( textField.getPreferredSize() );
textField.setLocation( mouseEvent.getPoint() );
panel.add( textField );
panel.repaint();
代码示例来源:origin: stackoverflow.com
public JTextFieldTest() {
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
String s = "It was an Abyssinian maid, and on her dulcimer she played,";
JTextField tf = new JTextField(s);
tf.setFont(new Font("Serif", Font.PLAIN, 24));
tf.validate();
int h = tf.getPreferredSize().height;
tf.getCaret().setDot(0);
this.setPreferredSize(new Dimension(240, h));
this.add(tf);
}
内容来源于网络,如有侵权,请联系作者删除!