Example usage for javax.swing JFormattedTextField JFormattedTextField

List of usage examples for javax.swing JFormattedTextField JFormattedTextField

Introduction

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

Prototype

public JFormattedTextField() 

Source Link

Document

Creates a JFormattedTextField with no AbstractFormatterFactory.

Usage

From source file:qrcode.JavaQR.java

@Override
public void run() {

    setLayout(new BorderLayout());

    JPanel topPanel = new JPanel();
    JPanel centerPanel = new JPanel();
    JPanel bottomPanel = new JPanel();

    topPanel.setLayout(new GridLayout(0, 1));
    topPanel.setBorder(BorderFactory.createTitledBorder("Input Data"));

    JPanel rowTopPanel = new JPanel();
    rowTopPanel.setLayout(new GridLayout(0, 2));

    JLabel accKey = new JLabel("Access Key");
    JTextField accField = new JTextField(5);

    accField.setEditable(false);/*from w w w .  j  a  v a2s .com*/
    accField.setText(Data.accessKey);

    JLabel regNo = new JLabel("Registration Number");
    JTextField regField = new JTextField(5);

    regField.setEditable(false);
    regField.setText(Data.registrationNumber);

    JLabel licNo = new JLabel("License Number");
    JFormattedTextField licField = new JFormattedTextField();

    licField.setEditable(false);
    licField.setText(Data.licenseNumber);

    rowTopPanel.add(accKey);
    rowTopPanel.add(accField);
    rowTopPanel.add(regNo);
    rowTopPanel.add(regField);
    rowTopPanel.add(licNo);
    rowTopPanel.add(licField);

    topPanel.add(rowTopPanel);

    centerPanel.setLayout(new GridLayout(0, 1));
    centerPanel.setBorder(BorderFactory.createTitledBorder("QR Code"));

    JPanel rowCenPanel = new JPanel();
    rowCenPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

    JButton genBtn = new JButton("Download QR Code");
    JButton homeBtn = new JButton("Back to Start");

    String accessKey = accField.getText().toString();
    String regKey = regField.getText().toString();
    String licKey = licField.getText().toString();
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("accessKey", accessKey);
        jsonObject.put("registrationNumber", regKey);
        jsonObject.put("licenseNumber", licKey);
    } catch (JSONException e1) {
        e1.printStackTrace();
    }

    QRLogic qrGen = new QRLogic();
    BufferedImage image = qrGen.generateQR(jsonObject);
    centerPanel.add(new JLabel(new ImageIcon(image)));

    bottomPanel.setLayout(new GridLayout(2, 1));

    rowCenPanel.add(homeBtn);
    rowCenPanel.add(genBtn);
    bottomPanel.add(rowCenPanel);
    add(topPanel, BorderLayout.NORTH);
    add(bottomPanel, BorderLayout.SOUTH);
    add(centerPanel, BorderLayout.CENTER);
    Data.mainFrame.setSize(1000, 500);

    genBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Date date = new Date();
            String newDate = new SimpleDateFormat("yyyy-MM-dd h-m-a").format(date);
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            File myFile = new File(Data.registrationNumber + ".png");
            fileChooser.setSelectedFile(myFile);
            fileChooser.showSaveDialog(null);
            String dlDir = fileChooser.getSelectedFile().getPath();
            System.out.println(dlDir);
            String fileName = fileChooser.getSelectedFile().getName();
            String filePath = "";
            if (fileName != null) {
                filePath = dlDir + ".png";
            } else {
                filePath = dlDir + "/" + Data.registrationNumber + ".png";
            }

            String fileType = "png";
            myFile = new File(filePath);

            if (dlDir != null) {

                try {
                    ImageIO.write(image, fileType, myFile);
                    JOptionPane.showMessageDialog(Data.mainFrame, "QR Code Saved in " + dlDir);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

            }
        }
    });

    homeBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Data.mainFrame.showPanel("inventory");
        }
    });

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e1) {
        e1.printStackTrace();
    } catch (InstantiationException e1) {
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        e1.printStackTrace();
    } catch (UnsupportedLookAndFeelException e1) {
        e1.printStackTrace();
    }

}

From source file:savant.plugin.ToolSettingsPanel.java

private void addArgumentToPanel(ToolArgument arg, int row) {
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.gridy = row;/* w  w w  . ja v  a  2 s .c  o  m*/
    JComponent widget = null;
    if (arg.type == ToolArgument.Type.BOOL) {
        gbc.gridx = 2;
        gbc.anchor = GridBagConstraints.WEST;
        addWidget(arg, new BoolCheck(arg), gbc);
    } else {
        gbc.gridx = 1;
        gbc.anchor = GridBagConstraints.EAST;
        JLabel nameLabel = new JLabel(arg.name + ":");
        add(nameLabel, gbc);

        gbc.gridx = 2;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.weightx = 1.0;
        JTextField field = null;
        switch (arg.type) {
        case INT:
            field = new JFormattedTextField();
            ((JFormattedTextField) field).setValue(Integer.valueOf(arg.value != null ? arg.value : "0"));
            field.setColumns(5);
            addField(arg, field, gbc);
            break;
        case FLOAT:
            field = new JFormattedTextField();
            ((JFormattedTextField) field).setValue(Double.valueOf(arg.value != null ? arg.value : "0.0"));
            field.setColumns(10);
            addField(arg, field, gbc);
            break;
        case OUTPUT_FILE:
            gbc.gridwidth = 1;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            field = new JTextField(arg.value);
            addField(arg, field, gbc);

            gbc.gridx = 3;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            gbc.weightx = 0.0;
            JCheckBox loadCheck = new JCheckBox("Load upon Completion", true);
            loadCheck.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    tool.loadUponCompletion = ((JCheckBox) ae.getSource()).isSelected();
                }
            });
            add(loadCheck, gbc);
            break;
        case RANGE:
            field = new JTextField();
            field.setColumns(25);
            LocationController.getInstance().addListener(new RangeUpdater(field));
            addField(arg, field, gbc);
            break;
        case LIST:
            addWidget(arg, new StringCombo(arg), gbc);
            break;
        case MULTI:
            gbc.fill = GridBagConstraints.HORIZONTAL;
            addWidget(arg, new MultiCheckGrid(arg), gbc);
            break;
        case BAM_INPUT_FILE:
            TrackUtils.addTrackListener(
                    (TrackCombo) addWidget(arg, new TrackCombo(arg, DataFormat.ALIGNMENT), gbc));
            break;
        case FASTA_INPUT_FILE:
            TrackUtils.addTrackListener(
                    (TrackCombo) addWidget(arg, new TrackCombo(arg, DataFormat.SEQUENCE), gbc));
            break;
        }
    }
}