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(int columns) 

Source Link

Document

Constructs a new empty TextField with the specified number of columns.

Usage

From source file:org.apache.shiro.samples.spring.ui.WebStartView.java

public void afterPropertiesSet() throws Exception {
    ClassPathResource resource = new ClassPathResource("logo.png");
    ImageIcon icon = new ImageIcon(resource.getURL());
    JLabel logo = new JLabel(icon);

    valueField = new JTextField(20);
    updateValueLabel();//w  w w  .  j a  v a  2 s .  c  om

    saveButton = new JButton("Save Value");
    saveButton.addActionListener(this);

    refreshButton = new JButton("Refresh Value");
    refreshButton.addActionListener(this);

    JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    valuePanel.add(valueField);
    valuePanel.add(saveButton);
    valuePanel.add(refreshButton);

    secureMethod1Button = new JButton("Method #1");
    secureMethod1Button.addActionListener(this);

    secureMethod2Button = new JButton("Method #2");
    secureMethod2Button.addActionListener(this);

    secureMethod3Button = new JButton("Method #3");
    secureMethod3Button.addActionListener(this);

    JPanel methodPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    methodPanel.add(secureMethod1Button);
    methodPanel.add(secureMethod2Button);
    methodPanel.add(secureMethod3Button);

    frame = new JFrame("Apache Shiro Sample Application");
    frame.setSize(500, 200);

    Container panel = frame.getContentPane();
    panel.setLayout(new BorderLayout());
    panel.add(logo, BorderLayout.NORTH);
    panel.add(valuePanel, BorderLayout.CENTER);
    panel.add(methodPanel, BorderLayout.SOUTH);

    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
}

From source file:fi.elfcloud.client.dialog.ModifyDataItemDialog.java

public ModifyDataItemDialog(JFrame parent, HashMap<String, String> metaMap, String diName) {
    super(parent, true);
    setTitle(Messages.getString("ModifyDataItemDialog.window_title") + diName); //$NON-NLS-1$
    this.metamap = metaMap;
    tagVector = new Vector<String>();
    setLocationRelativeTo(parent);// w ww .  j a va 2s  . c o  m
    panel.setLayout(new GridBagLayout());
    GridBagConstraints cs = new GridBagConstraints();
    cs.insets = new Insets(0, 0, 5, 0);

    lblName = new JLabel(Messages.getString("ModifyDataItemDialog.label_name")); //$NON-NLS-1$
    cs.gridx = 0;
    cs.gridy = 0;
    cs.fill = GridBagConstraints.HORIZONTAL;
    cs.gridwidth = 1;
    cs.weightx = 0;
    panel.add(lblName, cs);

    name = new JTextField(getWidth());
    cs.gridx = GridBagConstraints.RELATIVE;
    cs.gridy = 0;
    cs.fill = GridBagConstraints.HORIZONTAL;
    cs.gridwidth = 2;
    cs.weightx = 1.0;
    name.setText(diName);
    panel.add(name, cs);

    lblDescription = new JLabel(Messages.getString("ModifyDataItemDialog.label_description")); //$NON-NLS-1$
    cs.gridx = 0;
    cs.gridy = 1;
    cs.gridwidth = 1;
    cs.fill = GridBagConstraints.HORIZONTAL;
    cs.weightx = 0;
    panel.add(lblDescription, cs);

    description = new JTextField(getWidth());
    cs.gridx = GridBagConstraints.RELATIVE;
    cs.gridy = 1;
    cs.gridwidth = 2;
    cs.fill = GridBagConstraints.HORIZONTAL;
    cs.weightx = 1.0;
    description.setText(metaMap.get("DSC")); //$NON-NLS-1$
    panel.add(description, cs);

    lblTags = new JLabel(Messages.getString("ModifyDataItemDialog.label_tags")); //$NON-NLS-1$
    cs.gridx = 0;
    cs.gridy = 2;
    cs.gridwidth = 1;
    cs.fill = GridBagConstraints.HORIZONTAL;
    cs.weightx = 0;
    panel.add(lblTags, cs);

    tags = new JTextField(getWidth());
    cs.gridx = GridBagConstraints.RELATIVE;
    cs.gridy = 2;
    cs.fill = GridBagConstraints.HORIZONTAL;
    cs.weightx = 1.0;
    panel.add(tags, cs);

    JButton addButton = new JButton(Messages.getString("ModifyDataItemDialog.button_add_tag")); //$NON-NLS-1$
    cs.gridx = GridBagConstraints.RELATIVE;
    cs.gridy = 2;
    cs.gridwidth = 1;
    cs.weightx = 0;
    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String tagText = tags.getText().trim();
            if (!tagText.equals("")) { //$NON-NLS-1$
                addTags(tagText);
            }
            tags.setText(""); //$NON-NLS-1$

            checkboxPanel.revalidate();
            checkboxPanel.repaint();
        }
    });
    panel.add(addButton, cs);

    checkboxPanel = new JPanel(new WrapLayout(FlowLayout.LEFT));
    checkboxPanel.setSize(new Dimension(320, 1));
    try {
        addTags(metamap.get("TGS")); //$NON-NLS-1$
    } catch (NullPointerException e) {
        // No existing tags
    }
    panel.setBorder(new EmptyBorder(5, 5, 0, 5));
    getContentPane().add(panel, BorderLayout.NORTH);
    scrollPane = new JScrollPane(checkboxPanel);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setBorder(null);
    getContentPane().add(scrollPane, BorderLayout.CENTER);

    JButton generateButton = new JButton(Messages.getString("ModifyDataItemDialog.button_save")); //$NON-NLS-1$
    generateButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (tags.getText().length() > 0) {
                addTags(tags.getText());
            }
            answer = true;
            setVisible(false);
        }
    });
    JButton cancelButton = new JButton(Messages.getString("ModifyDataItemDialog.button_cancel")); //$NON-NLS-1$
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            answer = false;
            setVisible(false);
        }
    });
    JPanel bp = new JPanel();
    bp.add(generateButton);
    bp.add(cancelButton);
    getContentPane().add(bp, BorderLayout.PAGE_END);

    setMinimumSize(new Dimension(320, 350));
    pack();
}

From source file:EditableTree.java

public EditableTree() {
    DefaultMutableTreeNode forums = new DefaultMutableTreeNode("A");
    forums.add(new DefaultMutableTreeNode("B"));
    DefaultMutableTreeNode articles = new DefaultMutableTreeNode("E");
    articles.add(new DefaultMutableTreeNode("F"));
    DefaultMutableTreeNode examples = new DefaultMutableTreeNode("G");
    examples.add(new DefaultMutableTreeNode("H"));

    m_rootNode.add(forums);/*from  ww  w. j a  v a 2 s . co  m*/
    m_rootNode.add(articles);
    m_rootNode.add(examples);

    m_tree.setEditable(true);
    m_tree.setSelectionRow(0);

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

    JPanel panel = new JPanel();

    m_addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree.getLastSelectedPathComponent();
            if (selNode == null) {
                return;
            }
            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New Node");
            m_model.insertNodeInto(newNode, selNode, selNode.getChildCount());

            TreeNode[] nodes = m_model.getPathToRoot(newNode);
            TreePath path = new TreePath(nodes);
            m_tree.scrollPathToVisible(path);
            m_tree.setSelectionPath(path);
            m_tree.startEditingAtPath(path);
        }
    });
    panel.add(m_addButton);

    m_delButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) m_tree.getLastSelectedPathComponent();
            removeNode(selNode);
        }
    });
    panel.add(m_delButton);

    JPanel searchPanel = new JPanel();
    searchPanel.setBorder(BorderFactory.createEtchedBorder());

    m_searchText = new JTextField(10);
    searchPanel.add(m_searchText);

    m_searchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode node = searchNode(m_searchText.getText());
            if (node != null) {
                TreeNode[] nodes = m_model.getPathToRoot(node);
                TreePath path = new TreePath(nodes);
                m_tree.scrollPathToVisible(path);
                m_tree.setSelectionPath(path);
            } else {
                System.out.println("Node with string " + m_searchText.getText() + " not found");
            }
        }
    });
    searchPanel.add(m_searchButton);

    m_searchAndDeleteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode node = searchNode(m_searchText.getText());
            if (node != null) {
                removeNode(node);
            } else {
                System.out.println("Node with string " + m_searchText.getText() + " not found");
            }
        }
    });
    searchPanel.add(m_searchAndDeleteButton);
    panel.add(searchPanel);
    getContentPane().add(panel, BorderLayout.SOUTH);
    setSize(700, 400);
    setVisible(true);
}

From source file:components.ListDemo.java

public ListDemo() {
    super(new BorderLayout());

    listModel = new DefaultListModel();
    listModel.addElement("Jane Doe");
    listModel.addElement("John Smith");
    listModel.addElement("Kathy Green");

    //Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);//from w  w  w . j av a  2  s .  c  o  m
    list.addListSelectionListener(this);
    list.setVisibleRowCount(5);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton hireButton = new JButton(hireString);
    HireListener hireListener = new HireListener(hireButton);
    hireButton.setActionCommand(hireString);
    hireButton.addActionListener(hireListener);
    hireButton.setEnabled(false);

    fireButton = new JButton(fireString);
    fireButton.setActionCommand(fireString);
    fireButton.addActionListener(new FireListener());

    employeeName = new JTextField(10);
    employeeName.addActionListener(hireListener);
    employeeName.getDocument().addDocumentListener(hireListener);
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();

    //Create a panel that uses BoxLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.add(fireButton);
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(new JSeparator(SwingConstants.VERTICAL));
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(employeeName);
    buttonPane.add(hireButton);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    add(listScrollPane, BorderLayout.CENTER);
    add(buttonPane, BorderLayout.PAGE_END);
}

From source file:CelsiusConverter.java

private void addWidgets() {
    // Create widgets.
    tempCelsius = new JTextField(2);
    celsiusLabel = new JLabel("Celsius", SwingConstants.LEFT);
    convertTemp = new JButton("Convert...");
    fahrenheitLabel = new JLabel("Fahrenheit", SwingConstants.LEFT);

    // Listen to events from Convert button.
    convertTemp.addActionListener(this);

    // Add widgets to container.
    converterPanel.add(tempCelsius);//  ww  w  .  j a  va  2s .c  om
    converterPanel.add(celsiusLabel);
    converterPanel.add(convertTemp);
    converterPanel.add(fahrenheitLabel);

    celsiusLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    fahrenheitLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

}

From source file:gui.FormFrame.java

public void init() throws PaysNotFoundException {

    finish = new JButton(usage);

    //Init text fields
    if (argpays != null) {
        IDJTF = new JTextField(String.valueOf(argpays.getID()));
        indicatifJTF = new JTextField(argpays.getIndicatif());
        libellefrJTF = new JTextField(argpays.getLibelleFr());
        libelleenJTF = new JTextField(argpays.getLibelleEn());
        nationaliteJTF = new JTextField(argpays.getNationalite());
        monnaie_codeJTF = new JTextField(argpays.getMonnaieCode());
        monnaie_pdJTF = new JTextField(String.valueOf(argpays.getMonnaiePerdiem()));
        drapeauJTF = new JTextField(argpays.getDrapeau());
        tauxJTF = new JTextField(String.valueOf(argpays.getTauxChange()));
        dangerJTF = new JTextField(String.valueOf(argpays.isDanger()));
        coords1JTF = new JTextField(argpays.getCoords1());
        coords2JTF = new JTextField(argpays.getCoords2());
        coords3JTF = new JTextField(argpays.getCoords3());
        coords4JTF = new JTextField(argpays.getCoords4());
        coords5JTF = new JTextField(argpays.getCoords5());

    } else {/*  ww  w  .  j a  va 2  s  .  com*/
        IDJTF = new JTextField();
        indicatifJTF = new JTextField();
        libellefrJTF = new JTextField();
        libelleenJTF = new JTextField();
        nationaliteJTF = new JTextField();
        monnaie_codeJTF = new JTextField();
        monnaie_pdJTF = new JTextField();
        drapeauJTF = new JTextField();
        tauxJTF = new JTextField();
        dangerJTF = new JTextField();
        coords1JTF = new JTextField();
        coords2JTF = new JTextField();
        coords3JTF = new JTextField();
        coords4JTF = new JTextField();
        coords5JTF = new JTextField();
    }
    //init jlabels
    IDJL = new JLabel("ID");
    indicatifJL = new JLabel("Indicatif");
    libellefrJL = new JLabel("LibelleFR");
    libelleenJL = new JLabel("LibelleEN");
    nationaliteJL = new JLabel("Nationalit");
    monnaie_codeJL = new JLabel("Code Monnaie");
    monnaie_pdJL = new JLabel("Monnaie per diem");
    drapeauJL = new JLabel("Drapeau");
    tauxJL = new JLabel("Taux");
    dangerJL = new JLabel("danger (boolean)");
    coords1JL = new JLabel("c1");
    coords2JL = new JLabel("c2");
    coords3JL = new JLabel("c3");
    coords4JL = new JLabel("c4");
    coords5JL = new JLabel("c5");

    //finish.setEnabled(false);
    finish.addActionListener(this);
    mainPanel.setLayout(new GridLayout(1, 2));
    //formPanel construction pour l'ajout
    if (usage.equals("add") || argpays != null) {
        formPanel.setLayout(new GridLayout(16, 2));
        formPanel.add(IDJL);
        formPanel.add(IDJTF);
        formPanel.add(indicatifJL);
        formPanel.add(indicatifJTF);
        formPanel.add(libellefrJL);
        formPanel.add(libellefrJTF);
        formPanel.add(libelleenJL);
        formPanel.add(libelleenJTF);
        formPanel.add(nationaliteJL);
        formPanel.add(nationaliteJTF);
        formPanel.add(monnaie_codeJL);
        formPanel.add(monnaie_codeJTF);
        formPanel.add(monnaie_pdJL);
        formPanel.add(monnaie_pdJTF);
        formPanel.add(tauxJL);
        formPanel.add(tauxJTF);
        formPanel.add(dangerJL);
        formPanel.add(dangerJTF);
        formPanel.add(drapeauJL);
        formPanel.add(drapeauJTF);
        formPanel.add(coords1JL);
        formPanel.add(coords1JTF);
        formPanel.add(coords2JL);
        formPanel.add(coords2JTF);
        formPanel.add(coords3JL);
        formPanel.add(coords3JTF);
        formPanel.add(coords4JL);
        formPanel.add(coords4JTF);
        formPanel.add(coords5JL);
        formPanel.add(coords5JTF);

    } else {
        JCB = new JComboBox();
        //menu droulant de choix
        ListableBeanFactory bf;
        bf = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
        IPaysMetier instance = (IPaysMetier) bf.getBean("paysMetier");
        List<Pays> result = instance.findAllPays();
        for (Pays pays : result) {
            JCB.addItem(pays.getLibelleFr());
            System.out.println("libelle : " + pays.getLibelleFr());
        }
        formPanel.setLayout(new FlowLayout());
        formPanel.add(JCB);
    }

    mainPanel.add(formPanel);
    mainPanel.add(finish);
    mainPanel.setSize(new Dimension(600, 320));
    this.revalidate();
    this.setVisible(true);
    this.pack();
}

From source file:CelsiusConverter2.java

private void addWidgets() {
    // Create widgets.

    ImageIcon icon = new ImageIcon("images/convert.gif", "Convert temperature");
    tempCelsius = new JTextField(2);
    celsiusLabel = new JLabel("Celsius", SwingConstants.LEFT);
    convertTemp = new JButton(icon);
    fahrenheitLabel = new JLabel("Fahrenheit", SwingConstants.LEFT);

    celsiusLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    fahrenheitLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // Listen to events from Convert button.
    convertTemp.addActionListener(this);

    // Add widgets to container.
    converterPanel.add(tempCelsius);//from ww w . j a v  a  2 s . co m
    converterPanel.add(celsiusLabel);
    converterPanel.add(convertTemp);
    converterPanel.add(fahrenheitLabel);
}