Example usage for javax.swing JTextField JTextField

List of usage examples for javax.swing JTextField JTextField

Introduction

In this page you can find the example usage for javax.swing JTextField JTextField.

Prototype

public JTextField() 

Source Link

Document

Constructs a new TextField.

Usage

From source file:TextForm.java

public TextForm(String[] labels, char[] mnemonics, int[] widths, String[] tips) {
    super(new BorderLayout());
    JPanel labelPanel = new JPanel(new GridLayout(labels.length, 1));
    JPanel fieldPanel = new JPanel(new GridLayout(labels.length, 1));
    add(labelPanel, BorderLayout.WEST);
    add(fieldPanel, BorderLayout.CENTER);
    fields = new JTextField[labels.length];

    for (int i = 0; i < labels.length; i += 1) {
        fields[i] = new JTextField();
        if (i < tips.length)
            fields[i].setToolTipText(tips[i]);
        if (i < widths.length)
            fields[i].setColumns(widths[i]);

        JLabel lab = new JLabel(labels[i], JLabel.RIGHT);
        lab.setLabelFor(fields[i]);/*  w  ww . j  ava  2s  .  c om*/
        if (i < mnemonics.length)
            lab.setDisplayedMnemonic(mnemonics[i]);

        labelPanel.add(lab);
        JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
        p.add(fields[i]);
        fieldPanel.add(p);
    }
}

From source file:Main.java

public MyEditor() {
    super(new JTextField());
}

From source file:com.gs.obevo.util.inputreader.DialogInputReader.java

@Override
public String readLine(String promptMessage) {
    final JTextField juf = new JTextField();
    JOptionPane juop = new JOptionPane(juf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog userDialog = juop.createDialog(promptMessage);
    userDialog.addComponentListener(new ComponentAdapter() {
        @Override// w  w  w .j  a  v a2 s .c o  m
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    juf.requestFocusInWindow();
                }
            });
        }
    });
    userDialog.setVisible(true);
    int uresult = (Integer) juop.getValue();
    userDialog.dispose();
    String userName = null;
    if (uresult == JOptionPane.OK_OPTION) {
        userName = new String(juf.getText());
    }

    if (StringUtils.isEmpty(userName)) {
        return null;
    } else {
        return userName;
    }
}

From source file:Main.java

public TabPanel() {
    JPanel innerPanel = new JPanel();
    innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS));
    int USER_INPUT = 10;
    for (int i = 0; i < USER_INPUT; i++) {
        JPanel p = new JPanel(new BorderLayout());
        JLabel label = new JLabel("Label" + i);
        JTextField textArea = new JTextField();
        p.add(label, BorderLayout.NORTH);
        p.add(textArea, BorderLayout.CENTER);
        innerPanel.add(p);// w w  w  . j a  v a 2s.c o m
    }

    JScrollPane scrollPane = new JScrollPane(innerPanel);
    scrollPane.setPreferredSize(new Dimension(400, 200));
    this.add(scrollPane);
}

From source file:MainClass.java

public MainClass() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(350, 200);/*from w w  w. j a v a  2  s  .c  o m*/

    JTable table = new JTable(qtm);
    JScrollPane scrollpane = new JScrollPane(table);
    JPanel commandPanel = new JPanel();
    commandPanel.setLayout(new GridLayout(3, 2));
    commandPanel.add(new JLabel("Enter the Host URL: "));
    commandPanel.add(hostField = new JTextField());
    commandPanel.add(new JLabel("Enter your query: "));
    commandPanel.add(queryField = new JTextField());
    commandPanel.add(new JLabel("Click here to send: "));

    JButton jb = new JButton("Search");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            qtm.setHostURL(hostField.getText().trim());
            qtm.setQuery(queryField.getText().trim());
        }
    });
    commandPanel.add(jb);
    getContentPane().add(commandPanel, BorderLayout.NORTH);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}

From source file:EvenOddRowCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    JTextField editor = new JTextField();
    if (value != null)
        editor.setText(value.toString());
    editor.setBackground((row % 2 == 0) ? Color.white : Color.cyan);
    return editor;
}

From source file:com.mgmtp.perfload.loadprofiles.ui.component.DoubleCellEditor.java

public DoubleCellEditor() {
    super(new JTextField());
    final JTextField textField = (JTextField) getComponent();
    textField.setHorizontalAlignment(SwingConstants.RIGHT);
    delegate = new EditorDelegate() {
        @Override//ww  w.j a  v a 2s. c om
        public void setValue(final Object value) {
            textField.setText(value != null ? FORMAT.format(value) : null);
        }

        @Override
        public Object getCellEditorValue() {
            return textField.getText();
        }
    };
    textField.addActionListener(delegate);
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplateTreeTableCellEditor.java

public CodeTemplateTreeTableCellEditor(CodeTemplatePanel parent) {
    super(new JTextField());
    this.parent = parent;
    panel = new OffsetPanel(new MigLayout("insets 0, novisualpadding, hidemode 3, fill"));
    field = (JTextField) editorComponent;
    panel.add(field, "grow, push");
}

From source file:com.mgmtp.perfload.loadprofiles.ui.component.StringCellEditor.java

public StringCellEditor(final JTable table, final List<? extends AbstractNamedObject<?>> objects) {
    super(new JTextField());
    this.table = table;
    this.objects = objects;
}

From source file:DatabaseTest.java

public DatabaseTest() {
    super("Database Test Frame");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(350, 200);/*from  w w w. j  a v  a2s. c o  m*/

    qtm = new QueryTableModel();
    JTable table = new JTable(qtm);
    JScrollPane scrollpane = new JScrollPane(table);
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3, 2));
    p1.add(new JLabel("Enter the Host URL: "));
    p1.add(hostField = new JTextField());
    p1.add(new JLabel("Enter your query: "));
    p1.add(queryField = new JTextField());
    p1.add(new JLabel("Click here to send: "));

    JButton jb = new JButton("Search");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            qtm.setHostURL(hostField.getText().trim());
            qtm.setQuery(queryField.getText().trim());
        }
    });
    p1.add(jb);
    getContentPane().add(p1, BorderLayout.NORTH);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}