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:com.cactus.ClientLoginGUI.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor./*w w w  .  j  a va  2 s .  co m*/
 */
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    this.pack();
    this.setLocationRelativeTo(null);

    Username_TextField = new JTextField();
    Password_TextField = new JPasswordField();
    Username_Label = new JLabel();
    Password_label = new JLabel();
    Login_Button = new JButton();
    Register_Button = new JButton();

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    Username_TextField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Username_TextFieldActionPerformed(evt);
        }
    });

    Password_TextField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Password_TextFieldActionPerformed(evt);
        }
    });

    Username_Label.setText("Username:");

    Password_label.setText("Password:");

    Login_Button.setText("Login");
    Login_Button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            try {
                Login_ButtonActionPerformed(evt);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });

    Register_Button.setText("Register");
    Register_Button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            try {
                Register_ButtonActionPerformed(evt);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });

    javax.swing.GroupLayout layout = new GroupLayout(getContentPane());
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addGap(101)
            .addGroup(layout.createParallelGroup(Alignment.LEADING, false).addComponent(Password_label)
                    .addComponent(Username_TextField)
                    .addComponent(Password_TextField, GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup().addComponent(Register_Button)
                            .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(Login_Button))
                    .addComponent(Username_Label, GroupLayout.PREFERRED_SIZE, 109, GroupLayout.PREFERRED_SIZE))
            .addContainerGap(128, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addGap(71).addComponent(Username_Label)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(Username_TextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addGap(27).addComponent(Password_label).addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(Password_TextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addGap(33).addGroup(layout.createParallelGroup(Alignment.BASELINE)
                            .addComponent(Register_Button).addComponent(Login_Button))
                    .addContainerGap(48, Short.MAX_VALUE)));
    getContentPane().setLayout(layout);

    pack();
}

From source file:BoxLayoutTest.java

public Box createBox(boolean horizontal, boolean strutsAndGlue) {
    Box b;//from  www  .  j a  v  a2  s  .c  o  m
    if (horizontal)
        b = Box.createHorizontalBox();
    else
        b = Box.createVerticalBox();

    b.add(new JLabel("Name: "));
    b.add(new JTextField());

    if (strutsAndGlue)
        if (horizontal)
            b.add(Box.createHorizontalStrut(5));
        else
            b.add(Box.createVerticalStrut(5));

    b.add(new JLabel("Password: "));
    b.add(new JTextField());

    if (strutsAndGlue)
        b.add(Box.createGlue());

    b.add(new JButton("Ok"));

    return b;
}

From source file:com.mirth.connect.client.ui.attachments.IdentityAttachmentDialog.java

private void initComponents() {
    setBackground(UIConstants.BACKGROUND_COLOR);
    getContentPane().setBackground(getBackground());

    propertiesPanel = new JPanel();
    propertiesPanel.setBackground(getBackground());
    propertiesPanel.setBorder(BorderFactory.createTitledBorder("Properties"));

    mimeTypeLabel = new JLabel("MIME Type:");
    mimeTypeField = new JTextField();

    separator = new JSeparator(SwingConstants.HORIZONTAL);

    closeButton = new JButton("Close");
    closeButton.addActionListener(new ActionListener() {
        @Override/*from  www . ja  v a 2  s  .  co m*/
        public void actionPerformed(ActionEvent evt) {
            close();
        }
    });
}

From source file:de.peterspan.csv2db.ui.FileSelectionPanel.java

private JTextField getCsvFilenameTextField() {
    if (csvFileNameTextField == null) {
        csvFileNameTextField = new JTextField();
        csvFileNameTextField.setEnabled(false);
    }/*from   www  .  ja v  a 2 s  . c  o  m*/
    return csvFileNameTextField;
}

From source file:LDAPTest.java

public LDAPFrame() {
        setTitle("LDAPTest");
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

        JPanel northPanel = new JPanel();
        northPanel.setLayout(new java.awt.GridLayout(1, 2, 3, 1));
        northPanel.add(new JLabel("uid", SwingConstants.RIGHT));
        uidField = new JTextField();
        northPanel.add(uidField);//from w ww . ja  va  2 s. c o  m
        add(northPanel, BorderLayout.NORTH);

        JPanel buttonPanel = new JPanel();
        add(buttonPanel, BorderLayout.SOUTH);

        findButton = new JButton("Find");
        findButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                findEntry();
            }
        });
        buttonPanel.add(findButton);

        saveButton = new JButton("Save");
        saveButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                saveEntry();
            }
        });
        buttonPanel.add(saveButton);

        deleteButton = new JButton("Delete");
        deleteButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                deleteEntry();
            }
        });
        buttonPanel.add(deleteButton);

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent event) {
                try {
                    if (context != null)
                        context.close();
                } catch (NamingException e) {
                    e.printStackTrace();
                }
            }
        });
    }

From source file:cool.pandora.modeller.ui.BagTableFormBuilder.java

/**
 * add.//  w w w.j av  a 2 s .c  om
 *
 * @param isRequired boolean
 * @param label      String
 * @param checkbox   JComponent
 * @return addBinding
 */
public JComponent[] add(final boolean isRequired, final String label, final JComponent checkbox) {
    final JComponent textField = new JTextField();
    return addBinding(isRequired, label, textField, checkbox);
}

From source file:main.java.gui.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - BOHDAN Korinnyi
    test = new JFrame();
    label1 = new JLabel();
    textField1 = new JTextField();
    label2 = new JLabel();
    textField2 = new JTextField();
    label3 = new JLabel();
    label4 = new JLabel();
    textField3 = new JTextField();
    textField4 = new JTextField();
    button1 = new JButton();
    button2 = new JButton();
    label5 = new JLabel();
    label6 = new JLabel();

    //======== test ========
    {/*from  ww  w.j ava 2  s.  co  m*/
        test.setTitle("Pay mobile account");
        Container testContentPane = test.getContentPane();
        testContentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u0421\u0443\u043c\u0430");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 4f));
        testContentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(35, 30), label1.getPreferredSize()));

        //---- textField1 ----
        textField1.setColumns(10);
        testContentPane.add(textField1);
        textField1.setBounds(150, 30, 105, textField1.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u041d\u043e\u043c\u0435\u0440");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 4f));
        testContentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(35, 60), label2.getPreferredSize()));

        //---- textField2 ----
        textField2.setText("0674060606");
        textField2.setFont(textField2.getFont().deriveFont(textField2.getFont().getSize() + 2f));
        testContentPane.add(textField2);
        textField2.setBounds(150, 60, 105, textField2.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u041b\u043e\u0433\u0456\u043d");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 4f));
        testContentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(35, 95), label3.getPreferredSize()));

        //---- label4 ----
        label4.setText("\u041f\u0430\u0440\u043e\u043b\u044c");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 4f));
        testContentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(35, 125), label4.getPreferredSize()));
        testContentPane.add(textField3);
        textField3.setBounds(150, 95, 105, textField3.getPreferredSize().height);
        testContentPane.add(textField4);
        textField4.setBounds(150, 125, 105, 20);

        //---- button1 ----
        button1.setText("\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u0438");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getStyle() | Font.BOLD,
                button1.getFont().getSize() + 2f));
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String strTemp = textField1.getText();
                int cash = Integer.parseInt(strTemp);
                if (cash < 1) {
                    JOptionPane.showMessageDialog(null, "    '", "",
                            JOptionPane.OK_OPTION);
                    textField1.setText("0");
                } else if (textField3.getText().equals("test4") && textField4.getText().equals("12345")) {
                    check c = new check();
                    pay p = new pay();
                    getstatus g = new getstatus();
                    try {
                        c.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney()));
                        g.connection(c.PaymentStatusRequest());
                        p.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney()));
                        g.connection(c.PaymentStatusRequest());
                        information i = new information();
                        daoImplements h = new daoImplements();
                        long curTime = System.currentTimeMillis();
                        String curStringDate = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(curTime);

                        i.setIdTransaction(getTransaction.setGetTransaction());
                        i.setData(curStringDate);
                        i.setNumber(Integer.parseInt(getNumber()));
                        i.setSuma(Integer.parseInt(getMoney()));
                        i.setStatus(parserStatus.getStatusParsing());
                        h.addInfo(i);

                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (ParseException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "    ", "",
                            JOptionPane.OK_OPTION);
                    System.exit(0);
                }
            }

        });
        testContentPane.add(button1);
        button1.setBounds(150, 155, 115, 25);

        //---- button2 ----
        button2.setText("\u0406\u0441\u0442\u043e\u0440\u0456\u044f");
        button2.setFont(button2.getFont().deriveFont(button2.getFont().getStyle() | Font.BOLD,
                button2.getFont().getSize() + 2f));
        button2.setActionCommand("\u0406\u0441\u0442\u043e\u0440\u0456\u044f");
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tableData t = new tableData();
            }
        });
        testContentPane.add(button2);
        button2.setBounds(15, 155, 115, 25);

        //---- label5 ----
        label5.setText(
                "\u0422\u0435\u0441\u0442\u043e\u0432\u0438\u0439 \u0441\u0435\u0440\u0432\u0456\u0441 \u043f\u043e\u043f\u043e\u0432\u043d\u0435\u043d\u043d\u044f \u043c\u043e\u0431\u0456\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0445\u0443\u043d\u043a\u0443");
        label5.setFont(label5.getFont().deriveFont(label5.getFont().getStyle() & ~Font.ITALIC));
        testContentPane.add(label5);
        label5.setBounds(15, 0, 255, 20);

        //---- label6 ----
        label6.setText("38");
        label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 4f));
        testContentPane.add(label6);
        label6.setBounds(new Rectangle(new Point(130, 60), label6.getPreferredSize()));

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for (int i = 0; i < testContentPane.getComponentCount(); i++) {
                Rectangle bounds = testContentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = testContentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            testContentPane.setMinimumSize(preferredSize);
            testContentPane.setPreferredSize(preferredSize);
        }
        test.pack();
        test.setLocationRelativeTo(test.getOwner());
    }
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:gtu._work.ui.JermyP100UI.java

private void initGUI() {
    try {// w  ww.j  a v a 2s.co  m
        FlowLayout thisLayout = new FlowLayout();
        getContentPane().setLayout(thisLayout);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jLabel1 = new JLabel();
            getContentPane().add(jLabel1);
            jLabel1.setText("FileP100.xls");
            jLabel1.setPreferredSize(new java.awt.Dimension(68, 15));
        }
        {
            fileP100Text = new JTextField();
            JCommonUtil.jTextFieldSetFilePathMouseEvent(fileP100Text, false);
            getContentPane().add(fileP100Text);
            fileP100Text.setPreferredSize(new java.awt.Dimension(340, 22));
        }
        {
            label2 = new JLabel();
            getContentPane().add(label2);
            getContentPane().add(label2);
            label2.setText("RCDFP100.xls");
            label2.setPreferredSize(new java.awt.Dimension(84, 15));
        }
        {
            rcdfp100Text = new JTextField();
            JCommonUtil.jTextFieldSetFilePathMouseEvent(rcdfp100Text, false);
            getContentPane().add(rcdfp100Text);
            rcdfp100Text.setPreferredSize(new java.awt.Dimension(340, 22));
        }
        {
            executeBtn = new JButton();
            getContentPane().add(executeBtn);
            executeBtn.setText("\u7522\u751f\u532f\u51fa\u6a94");
            executeBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    if (StringUtils.isBlank(rcdfp100Text.getText())) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("RCDFP100.xls");
                        return;
                    }
                    File rcdfp100File = new File(StringUtils.defaultString(rcdfp100Text.getText()));
                    if (!rcdfp100File.exists()) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("RCDFP100.xls");
                        return;
                    }

                    if (StringUtils.isBlank(fileP100Text.getText())) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("FileP100.xls");
                        return;
                    }
                    File fileP100File = new File(StringUtils.defaultString(fileP100Text.getText()));
                    if (!rcdfp100File.exists()) {
                        JCommonUtil._jOptionPane_showMessageDialog_error("FileP100.xls");
                        return;
                    }

                    try {
                        TestForJermy test = new TestForJermy();
                        test.execute(fileP100File, rcdfp100File,
                                PropertiesUtil.getJarCurrentPath(JermyP100UI.class));
                        File outputFile = test.getOutputCvs();
                        JCommonUtil._jOptionPane_showMessageDialog_info(
                                ":\n" + outputFile.getAbsolutePath());
                    } catch (Exception ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
        }
        pack();
        this.setSize(457, 146);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:net.itransformers.topologyviewer.menu.handlers.graphFileMenuHandlers.SaveCurrentGraphMenuHandler.java

@Override
public void actionPerformed(ActionEvent e) {
    File path = frame.getPath();//from  w w  w .j a  v a 2s  .  c om

    if (path == null) {
        JOptionPane.showMessageDialog(frame, "Can not open graph before project has been opened.");
        return;
    }

    JTextField fileName = new JTextField();
    Object[] message = { "File name", fileName };
    String versionName = JOptionPane.showInputDialog("Enter output graph version");

    File networkPath = new File(path + File.separator + ProjectConstants.networkDirName);

    File versionPath = new File(networkPath, versionName);
    if (versionPath.exists()) {
        JOptionPane.showMessageDialog(frame, "Version already exists" + versionPath.getAbsolutePath());

        return;
    }

    if (!versionPath.mkdir()) {
        JOptionPane.showMessageDialog(frame, "Unable to create version path: " + versionPath.getAbsolutePath());
    }

    if ("undirected".equalsIgnoreCase(frame.getCurrentGraphViewerManager().getGraphType().toString())) {
        graphmlDir = new File(versionPath.getAbsolutePath(), ProjectConstants.undirectedGraphmlDirName);

    } else {
        graphmlDir = new File(versionPath.getAbsolutePath(), ProjectConstants.directedGraphmlDirName);

    }
    if (!graphmlDir.mkdir()) {
        JOptionPane.showMessageDialog(frame, "Unable to create version path:" + versionPath.getAbsolutePath(),
                "Error", JOptionPane.WARNING_MESSAGE);
        return;
    }

    Writer fileWriter;
    try {
        fileWriter = new FileWriter(new File(graphmlDir, ProjectConstants.networkGraphmlFileName));
    } catch (IOException e1) {
        JOptionPane.showMessageDialog(frame, "Unable to create network.graphml file:", "Error",
                JOptionPane.WARNING_MESSAGE);
        return;
    }
    GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent();
    final Graph<String, String> currentGraph = viewerPanel.getCurrentGraph();
    MyGraphMLWriter writer = new MyGraphMLWriter();
    writer.setGraphData(viewerPanel.getGraphmlLoader().getGraphMetadatas());
    writer.setVertexData(viewerPanel.getGraphmlLoader().getVertexMetadatas());
    writer.setEdgeData(viewerPanel.getGraphmlLoader().getEdgeMetadatas());
    writer.setEdgeIDs(new Transformer<String, String>() {

        @Override
        public String transform(String s) {
            Pair<String> endpoints = currentGraph.getEndpoints(s);
            String[] endpointsArr = new String[] { endpoints.getFirst(), endpoints.getSecond() };
            Arrays.sort(endpointsArr);
            return endpointsArr[0] + "_" + endpointsArr[1];
        }
    });
    boolean flag;
    try {
        writer.save(currentGraph, fileWriter);
        flag = true;

    } catch (IOException e1) {
        flag = false;
        JOptionPane.showMessageDialog(frame, "Unable to write graph file:" + e1.getMessage(), "Error",
                JOptionPane.WARNING_MESSAGE);

    }

}

From source file:FileTree2.java

public FileTree2() {
    super("Directories Tree [Popup Menus]");
    setSize(400, 300);/*from  ww  w  . j  a  v a2  s.co m*/

    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer"));

    DefaultMutableTreeNode node;
    File[] roots = File.listRoots();
    for (int k = 0; k < roots.length; k++) {
        node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k])));
        top.add(node);
        node.add(new DefaultMutableTreeNode(new Boolean(true)));
    }

    m_model = new DefaultTreeModel(top);
    m_tree = new JTree(m_model);

    m_tree.putClientProperty("JTree.lineStyle", "Angled");

    TreeCellRenderer renderer = new IconCellRenderer();
    m_tree.setCellRenderer(renderer);

    m_tree.addTreeExpansionListener(new DirExpansionListener());

    m_tree.addTreeSelectionListener(new DirSelectionListener());

    m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(false);

    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    getContentPane().add(s, BorderLayout.CENTER);

    m_display = new JTextField();
    m_display.setEditable(false);
    getContentPane().add(m_display, BorderLayout.NORTH);

    // NEW
    m_popup = new JPopupMenu();
    m_action = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (m_clickedPath == null)
                return;
            if (m_tree.isExpanded(m_clickedPath))
                m_tree.collapsePath(m_clickedPath);
            else
                m_tree.expandPath(m_clickedPath);
        }
    };
    m_popup.add(m_action);
    m_popup.addSeparator();

    Action a1 = new AbstractAction("Delete") {
        public void actionPerformed(ActionEvent e) {
            m_tree.repaint();
            JOptionPane.showMessageDialog(FileTree2.this, "Delete option is not implemented", "Info",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    };
    m_popup.add(a1);

    Action a2 = new AbstractAction("Rename") {
        public void actionPerformed(ActionEvent e) {
            m_tree.repaint();
            JOptionPane.showMessageDialog(FileTree2.this, "Rename option is not implemented", "Info",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    };
    m_popup.add(a2);
    m_tree.add(m_popup);
    m_tree.addMouseListener(new PopupTrigger());

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
}