List of usage examples for javax.swing JTextField getPreferredSize
public Dimension getPreferredSize()
Dimensions
needed for this TextField
. From source file:Main.java
public static void main(String[] args) { JTextField tf = new JTextField("mm"); tf.setPreferredSize(tf.getPreferredSize()); tf.setText(""); JPanel pHacked = new JPanel(); pHacked.add(tf);//from w w w. j a v a 2 s.c o m JPanel pStock = new JPanel(); pStock.add(new JTextField(2)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new java.awt.GridLayout(0, 1)); frame.add(pHacked); frame.add(pStock); frame.setSize(150, 150); frame.setVisible(true); tf.requestFocus(); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); Box b = Box.createVerticalBox(); JTextField field1 = new JTextField(); JTextField field2 = new JTextField(); field1.setMaximumSize(new Dimension(Integer.MAX_VALUE, field1.getPreferredSize().height)); field2.setMaximumSize(new Dimension(Integer.MAX_VALUE, field2.getPreferredSize().height)); b.add(field1);// www . j a va2s. com b.add(field2); b.add(Box.createVerticalGlue()); f.setContentPane(b); f.setSize(500, 200); f.setVisible(true); }
From source file:org.eclipse.swt.snippets.Snippet300.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("SWT and Swing DND Example"); GridLayout layout = new GridLayout(1, false); shell.setLayout(layout);/*from w w w. j a v a 2 s.c o m*/ Text swtText = new Text(shell, SWT.BORDER); swtText.setText("SWT Text"); GridData data = new GridData(GridData.FILL_HORIZONTAL); swtText.setLayoutData(data); setDragDrop(swtText); Composite comp = new Composite(shell, SWT.EMBEDDED); java.awt.Frame frame = SWT_AWT.new_Frame(comp); JTextField swingText = new JTextField(40); swingText.setText("Swing Text"); swingText.setDragEnabled(true); frame.add(swingText); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = swingText.getPreferredSize().height; comp.setLayoutData(data); shell.setSize(400, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Main.java
/** * Default textfield design.//from ww w .j av a2 s . co m * * @param requireMinWidth Whether the textfield should have a default min. width set. * @param contents Initial contents. * @return */ public static JTextField defaultTextField(boolean requireMinWidth, String contents) { JTextField jtf = new JTextField(contents); if (requireMinWidth) jtf.setPreferredSize(new Dimension(400, jtf.getPreferredSize().height)); jtf.setBorder(BorderFactory.createCompoundBorder(defaultLineBorder(), BorderFactory.createEmptyBorder(0, 5, 0, 0))); return jtf; }
From source file:Main.java
public Main() { super(null);/*from w w w. j ava 2 s. c om*/ JTextField tf = new JTextField(10); add(tf); Dimension d = tf.getPreferredSize(); tf.setBounds(10, 20, d.width, d.height); }
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel p = new JPanel(new BorderLayout()); JTextField tf = new JTextField(5); JLabel label = new JLabel(new ImageIcon("Test.gif")); label.setOpaque(true);//from w w w .j a va 2s . c o m label.setBackground(tf.getBackground()); label.setPreferredSize(new Dimension(label.getPreferredSize().width, tf.getPreferredSize().height)); p.setBorder(tf.getBorder()); tf.setBorder(null); p.add(label, BorderLayout.WEST); p.add(tf, BorderLayout.CENTER); JPanel p1 = new JPanel(); p1.add(p); getContentPane().add(p1); pack(); setLocationRelativeTo(null); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTextField.java
@Override protected JTextField createTextComponentImpl() { JTextField field = new FlushableTextField(); int height = (int) field.getPreferredSize().getHeight(); field.setPreferredSize(new Dimension(150, height)); return field; }
From source file:com.game.ui.views.WeaponEditorPanel.java
public void doGui() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JLabel noteLbl = new JLabel( "<html><div style='width : 500px;'>Pls select a value to choose an Weapon or you can create a new " + "Weapon entity below. Once selected a weapon, its' details will be available below</div></html>"); noteLbl.setAlignmentX(0);/*from w ww .j a v a 2 s .c o m*/ add(noteLbl); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (Item item : GameBean.weaponDetails) { if (item instanceof Weapon) { model.addElement(((Weapon) item).getName()); } } comboBox = new JComboBox(model); comboBox.setSelectedIndex(-1); comboBox.setMaximumSize(new Dimension(100, 30)); comboBox.setAlignmentX(0); comboBox.setActionCommand("dropDown"); comboBox.addActionListener(this); add(Box.createVerticalStrut(10)); add(comboBox); add(Box.createVerticalStrut(10)); JPanel panel1 = new JPanel(); panel1.setAlignmentX(0); panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel1.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(5, 5, 5, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 2; JLabel weaponDtsLbl = new JLabel("Weapon Details : "); weaponDtsLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); panel1.add(weaponDtsLbl, c); c.gridwidth = 1; c.gridy = 1; JLabel nameLbl = new JLabel("Name : "); panel1.add(nameLbl, c); c.gridx = 1; JTextField name = new JTextField(""); name.setColumns(20); panel1.add(name, c); c.gridx = 0; c.gridy = 2; JLabel weaponTypeLbl = new JLabel("Weapon Type : "); panel1.add(weaponTypeLbl, c); c.gridx = 1; JComboBox weaponType = new JComboBox(Configuration.weaponTypes); weaponType.setSelectedIndex(0); weaponType.setPreferredSize(name.getPreferredSize()); System.out.println(name.getPreferredSize()); panel1.add(weaponType, c); c.gridx = 0; c.gridy = 3; JLabel attackRangeLbl = new JLabel("Attack Range : "); panel1.add(attackRangeLbl, c); c.gridx = 1; JTextField attackRange = new JTextField(""); attackRange.setColumns(20); panel1.add(attackRange, c); c.gridx = 0; c.gridy = 4; JLabel attackPtsLbl = new JLabel("Attack Points : "); panel1.add(attackPtsLbl, c); c.gridx = 1; JTextField attackPts = new JTextField(""); attackPts.setColumns(20); panel1.add(attackPts, c); c.gridx = 0; c.gridy = 5; c.gridwidth = 2; JButton submit = new JButton("Save"); submit.addActionListener(this); submit.setActionCommand("button"); panel1.add(submit, c); c.gridx = 0; c.gridy = 6; c.gridwidth = 2; c.weighty = 0; c.weightx = 1; validationMess = new JLabel("Pls enter all the fields or pls choose a weapon from the drop down"); validationMess.setForeground(Color.red); validationMess.setVisible(false); panel1.add(validationMess, c); // c.fill = GridBagConstraints.BOTH; // c.gridy = 7; // c.weightx = 1; // c.weighty = 1; // panel1.add(new JLabel(""), c); panel1.setBorder(LineBorder.createGrayLineBorder()); add(panel1); add(Box.createVerticalGlue()); }
From source file:org.esa.beam.visat.toolviews.stat.HistogramPanel.java
private JPanel createOptionsPanel() { final JLabel numBinsLabel = new JLabel("#Bins:"); JTextField numBinsField = new JTextField(Integer.toString(NUM_BINS_DEFAULT)); numBinsField.setPreferredSize(new Dimension(50, numBinsField.getPreferredSize().height)); final JCheckBox histoLogCheck = new JCheckBox("Log10 scaled bins"); histoLogCheck.addActionListener(configChangeListener); bindingContext.getPropertySet().getDescriptor(PROPERTY_NAME_NUM_BINS) .setDescription("Set the number of bins in the histogram"); bindingContext.getPropertySet().getDescriptor(PROPERTY_NAME_NUM_BINS) .setValueRange(new ValueRange(2.0, 2048.0)); bindingContext.getPropertySet().getDescriptor(PROPERTY_NAME_NUM_BINS).setDefaultValue(NUM_BINS_DEFAULT); bindingContext.bind(PROPERTY_NAME_NUM_BINS, numBinsField); bindingContext.getPropertySet().getDescriptor(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM) .setDescription("Use log-10 scaled values for computation of histogram"); bindingContext.getPropertySet().getDescriptor(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM).setDefaultValue(false); bindingContext.bind(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM, histoLogCheck); log10HistEnablement = bindingContext.bindEnabledState(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM, true, new Enablement.Condition() { @Override/*from w w w . ja v a 2 s . c o m*/ public boolean evaluate(BindingContext bindingContext) { return getRaster() != null && getRaster().getStx().getMaximum() > 0; } }); PropertyChangeListener logChangeListener = new AxisControlChangeListener(); xAxisRangeControl.getBindingContext().addPropertyChangeListener(logChangeListener); xAxisRangeControl.getBindingContext().getPropertySet() .addProperty(bindingContext.getPropertySet().getProperty(PROPERTY_NAME_LOGARITHMIC_HISTOGRAM)); xAxisRangeControl.getBindingContext().getPropertySet() .addProperty(bindingContext.getPropertySet().getProperty(PROPERTY_NAME_LOG_SCALED)); xAxisRangeControl.getBindingContext().getPropertySet().getDescriptor(PROPERTY_NAME_LOG_SCALED) .setDescription("Toggle whether to use a logarithmic x-axis"); log10AxisEnablement = xAxisRangeControl.getBindingContext().bindEnabledState(PROPERTY_NAME_LOG_SCALED, true, new Enablement.Condition() { @Override public boolean evaluate(BindingContext bindingContext) { HistogramPanelModel.HistogramConfig currentConfig = createHistogramConfig(); boolean hasStx = model.hasStx(currentConfig); // log10 xAxis is enabled when current histogram exists and is NOT log10 scaled return dataset != null && hasStx && !model.getStx(currentConfig).isLogHistogram(); } }); JPanel dataSourceOptionsPanel = GridBagUtils.createPanel(); GridBagConstraints dataSourceOptionsConstraints = GridBagUtils .createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2"); GridBagUtils.addToPanel(dataSourceOptionsPanel, new JLabel(" "), dataSourceOptionsConstraints, "gridwidth=2,gridy=0,gridx=0,weightx=0"); GridBagUtils.addToPanel(dataSourceOptionsPanel, numBinsLabel, dataSourceOptionsConstraints, "insets.top=2,insets.left=4,gridwidth=1,gridy=1,gridx=0,weightx=1"); GridBagUtils.addToPanel(dataSourceOptionsPanel, numBinsField, dataSourceOptionsConstraints, "insets.top=0,insets.left=0,insets.right=2,gridwidth=1,gridy=1,gridx=1"); GridBagUtils.addToPanel(dataSourceOptionsPanel, histoLogCheck, dataSourceOptionsConstraints, "insets.right=0,gridwidth=2,gridy=2,gridx=0"); xAxisRangeControl.getBindingContext().bind(PROPERTY_NAME_LOG_SCALED, new JCheckBox("Log10 scaled")); xAxisRangeControl.getBindingContext().addPropertyChangeListener(PROPERTY_NAME_LOG_SCALED, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { ValueAxis oldAxis = chart.getXYPlot().getDomainAxis(); ValueAxis newAxis = StatisticChartStyling.updateScalingOfAxis((Boolean) evt.getNewValue(), oldAxis, true); chart.getXYPlot().setDomainAxis(newAxis); } }); JPanel displayOptionsPanel = GridBagUtils.createPanel(); GridBagConstraints displayOptionsConstraints = GridBagUtils .createConstraints("anchor=SOUTH,fill=HORIZONTAL,weightx=1"); GridBagUtils.addToPanel(displayOptionsPanel, xAxisRangeControl.getPanel(), displayOptionsConstraints, "gridy=2"); JPanel optionsPanel = GridBagUtils.createPanel(); GridBagConstraints gbc = GridBagUtils .createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1"); GridBagUtils.addToPanel(optionsPanel, dataSourceOptionsPanel, gbc, "gridy=0"); GridBagUtils.addToPanel(optionsPanel, new JPanel(), gbc, "gridy=1,fill=VERTICAL,weighty=1"); GridBagUtils.addToPanel(optionsPanel, displayOptionsPanel, gbc, "gridy=2,fill=HORIZONTAL,weighty=0"); GridBagUtils.addToPanel(optionsPanel, new JPanel(), gbc, "gridy=3,fill=VERTICAL,weighty=1"); GridBagUtils.addToPanel(optionsPanel, xAxisRangeControl.getBindingContext().getBinding(PROPERTY_NAME_LOG_SCALED).getComponents()[0], gbc, "gridy=4"); return optionsPanel; }
From source file:org.esa.snap.rcp.statistics.ScatterPlotPanel.java
private JPanel createInputParameterPanel() { final PropertyDescriptor boxSizeDescriptor = bindingContext.getPropertySet() .getDescriptor(PROPERTY_NAME_BOX_SIZE); boxSizeDescriptor.setValueRange(new ValueRange(1, 101)); boxSizeDescriptor.setAttribute("stepSize", 2); boxSizeDescriptor.setValidator((property, value) -> { if (((Number) value).intValue() % 2 == 0) { throw new ValidationException("Only odd values allowed as box size."); }//from ww w .j a v a2 s . c om }); final JSpinner boxSizeSpinner = new JSpinner(); bindingContext.bind(PROPERTY_NAME_BOX_SIZE, boxSizeSpinner); final JPanel boxSizePanel = new JPanel(new BorderLayout(5, 3)); boxSizePanel.add(new JLabel("Box size:"), BorderLayout.WEST); boxSizePanel.add(boxSizeSpinner); correlativeFieldSelector = new CorrelativeFieldSelector(bindingContext); final JPanel pointDataSourcePanel = new JPanel(new BorderLayout(5, 3)); pointDataSourcePanel.add(correlativeFieldSelector.pointDataSourceLabel, BorderLayout.NORTH); pointDataSourcePanel.add(correlativeFieldSelector.pointDataSourceList); final JPanel pointDataFieldPanel = new JPanel(new BorderLayout(5, 3)); pointDataFieldPanel.add(correlativeFieldSelector.dataFieldLabel, BorderLayout.NORTH); pointDataFieldPanel.add(correlativeFieldSelector.dataFieldList); final JCheckBox xLogCheck = new JCheckBox("Log10 scaled"); bindingContext.bind(PROPERTY_NAME_X_AXIS_LOG_SCALED, xLogCheck); final JPanel xAxisOptionPanel = new JPanel(new BorderLayout()); xAxisOptionPanel.add(xAxisRangeControl.getPanel()); xAxisOptionPanel.add(xLogCheck, BorderLayout.SOUTH); final JCheckBox yLogCheck = new JCheckBox("Log10 scaled"); bindingContext.bind(PROPERTY_NAME_Y_AXIS_LOG_SCALED, yLogCheck); final JPanel yAxisOptionPanel = new JPanel(new BorderLayout()); yAxisOptionPanel.add(yAxisRangeControl.getPanel()); yAxisOptionPanel.add(yLogCheck, BorderLayout.SOUTH); final JCheckBox acceptableCheck = new JCheckBox("Show tolerance range"); JLabel fieldPrefix = new JLabel("+/-"); final JTextField acceptableField = new JTextField(); acceptableField.setPreferredSize(new Dimension(40, acceptableField.getPreferredSize().height)); acceptableField.setHorizontalAlignment(JTextField.RIGHT); final JLabel percentLabel = new JLabel(" %"); bindingContext.bind(PROPERTY_NAME_SHOW_ACCEPTABLE_DEVIATION, acceptableCheck); bindingContext.bind(PROPERTY_NAME_ACCEPTABLE_DEVIATION, acceptableField); bindingContext.getBinding(PROPERTY_NAME_ACCEPTABLE_DEVIATION).addComponent(percentLabel); bindingContext.getBinding(PROPERTY_NAME_ACCEPTABLE_DEVIATION).addComponent(fieldPrefix); bindingContext.bindEnabledState(PROPERTY_NAME_ACCEPTABLE_DEVIATION, true, PROPERTY_NAME_SHOW_ACCEPTABLE_DEVIATION, true); final JPanel confidencePanel = GridBagUtils.createPanel(); GridBagConstraints confidencePanelConstraints = GridBagUtils .createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=5,weighty=0,weightx=1"); GridBagUtils.addToPanel(confidencePanel, acceptableCheck, confidencePanelConstraints, "gridy=0,gridwidth=3"); GridBagUtils.addToPanel(confidencePanel, fieldPrefix, confidencePanelConstraints, "weightx=0,insets.left=22,gridy=1,gridx=0,insets.top=4,gridwidth=1"); GridBagUtils.addToPanel(confidencePanel, acceptableField, confidencePanelConstraints, "weightx=1,gridx=1,insets.left=2,insets.top=2"); GridBagUtils.addToPanel(confidencePanel, percentLabel, confidencePanelConstraints, "weightx=0,gridx=2,insets.left=0,insets.top=4"); final JCheckBox regressionCheck = new JCheckBox("Show regression line"); bindingContext.bind(PROPERTY_NAME_SHOW_REGRESSION_LINE, regressionCheck); // UI arrangement JPanel middlePanel = GridBagUtils.createPanel(); GridBagConstraints middlePanelConstraints = GridBagUtils .createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=6,weighty=0,weightx=1"); GridBagUtils.addToPanel(middlePanel, boxSizePanel, middlePanelConstraints, "gridy=0,insets.left=6"); GridBagUtils.addToPanel(middlePanel, pointDataSourcePanel, middlePanelConstraints, "gridy=1"); GridBagUtils.addToPanel(middlePanel, pointDataFieldPanel, middlePanelConstraints, "gridy=2"); GridBagUtils.addToPanel(middlePanel, xAxisOptionPanel, middlePanelConstraints, "gridy=3,insets.left=0"); GridBagUtils.addToPanel(middlePanel, yAxisOptionPanel, middlePanelConstraints, "gridy=4"); GridBagUtils.addToPanel(middlePanel, new JSeparator(), middlePanelConstraints, "gridy=5,insets.left=4"); GridBagUtils.addToPanel(middlePanel, confidencePanel, middlePanelConstraints, "gridy=6,fill=HORIZONTAL,insets.left=-4"); GridBagUtils.addToPanel(middlePanel, regressionCheck, middlePanelConstraints, "gridy=7,insets.left=-4,insets.top=8"); return middlePanel; }