List of usage examples for javax.swing JTextField JTextField
public JTextField(int columns)
TextField
with the specified number of columns. From source file:Main.java
private JPanel create() { JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout);//from ww w . java2 s.co m layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); GroupLayout.ParallelGroup parallel = layout.createParallelGroup(); layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(parallel)); GroupLayout.SequentialGroup sequential = layout.createSequentialGroup(); layout.setVerticalGroup(sequential); for (int i = 0; i < NUM; i++) { labels[i] = new JLabel(String.valueOf(i + 1), JLabel.RIGHT); fields[i] = new JTextField(String.valueOf("" + (i + 1))); labels[i].setLabelFor(fields[i]); parallel.addGroup(layout.createSequentialGroup().addComponent(labels[i]).addComponent(fields[i])); sequential.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(labels[i]) .addComponent(fields[i])); layout.linkSize(SwingConstants.HORIZONTAL, labels[i], labels[0]); } return panel; }
From source file:EditorPaneExample1.java
public EditorPaneExample1() { super("JEditorPane Example 1"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(4, 4)); JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, "West"); textField = new JTextField(32); panel.add(textField, "Center"); getContentPane().add(panel, "South"); // Change page based on text field textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String url = textField.getText(); try { // Try to display the page pane.setPage(url);//ww w .j av a 2s. com } catch (IOException e) { JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url }, "File Open Error", JOptionPane.ERROR_MESSAGE); } } }); }
From source file:com.vrane.metaGlacier.gui.SNSTopicDialog.java
SNSTopicDialog() { super(Main.frame, true); JPanel mainPanel = new JPanel(new GridLayout(4, 2)); final JTextField topicNameJT = new JTextField(10); final JTextField emailJT = new JTextField(10); final JButton subscribeButton = new JButton("subscribe"); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 5)); mainPanel.add(new JLabel("topic name")); mainPanel.add(topicNameJT);/*from w w w .j a va2 s.c om*/ mainPanel.add(new JLabel("email")); mainPanel.add(emailJT); final String metadata_account_email = Main.frame.getMPCUser(); if (metadata_account_email != null) { emailJT.setText(metadata_account_email); } mainPanel.add(new JLabel()); mainPanel.add(subscribeButton); subscribeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { final String email = emailJT.getText(); final String name = topicNameJT.getText(); boolean success = false; if (!EmailValidator.getInstance().isValid(email)) { JOptionPane.showMessageDialog(null, "Invalid email address"); return; } try { success = new SNSTopic().createTopic(name, email); } catch (Exception ex) { LGR.log(Level.SEVERE, null, ex); } if (success) { JOptionPane.showMessageDialog(null, "Please check your email to confirm"); dispose(); return; } JOptionPane.showMessageDialog(null, "Error subscribing"); } }); add(mainPanel); pack(); setLocationRelativeTo(Main.frame); setVisible(true); }
From source file:Main.java
private JPanel createTabbedPanel() { JPanel panel = new JPanel(new BorderLayout()); JTextField field = new JTextField(50); JEditorPane pane = new JEditorPane(); pane.setPreferredSize(new Dimension(700, 500)); panel.add(field, BorderLayout.NORTH); panel.add(pane, BorderLayout.CENTER); return panel; }
From source file:layout.SpringGrid.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from ww w. jav a 2 s . c o m*/ */ private static void createAndShowGUI() { //Create the panel and populate it. JPanel panel = new JPanel(new SpringLayout()); for (int i = 0; i < 9; i++) { JTextField textField = new JTextField(Integer.toString(i)); //Make the 4th field extra big. if (i == 4) { textField.setText("This one is extra long."); } panel.add(textField); } //Lay out the panel. SpringUtilities.makeGrid(panel, 3, 3, //rows, cols 5, 5, //initialX, initialY 5, 5);//xPad, yPad //Create and set up the window. JFrame frame = new JFrame("SpringGrid"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. panel.setOpaque(true); //content panes must be opaque frame.setContentPane(panel); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:org.jdal.swing.report.DefaultReportParameterEditor.java
public JComponent getEditor() { if (editor == null) editor = new JTextField(15); return editor; }
From source file:com.vrane.metaGlacier.gui.MetaDataSignUpDialog.java
MetaDataSignUpDialog() { super(Main.frame, true); JPanel signUpPanel = new JPanel(new GridLayout(4, 2)); final JTextField nameJT = new JTextField(10); final JTextField emailJT = new JTextField(10); final JTextField emailJT1 = new JTextField(10); final JButton signUpButton = new JButton("Sign up"); signUpPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 5)); signUpPanel.add(new JLabel("name (optional)")); signUpPanel.add(nameJT);// www .j a v a2 s . co m signUpPanel.add(new JLabel("email")); signUpPanel.add(emailJT); signUpPanel.add(new JLabel("email again")); signUpPanel.add(emailJT1); signUpPanel.add(new JLabel()); signUpPanel.add(signUpButton); signUpButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { final String email = emailJT.getText(); final String email1 = emailJT1.getText(); final String name = nameJT.getText(); boolean success = false; if (!email.equals(email1)) { JOptionPane.showMessageDialog(null, "Email addresses do not match"); return; } if (!EmailValidator.getInstance().isValid(email)) { JOptionPane.showMessageDialog(null, "Invalid email address"); return; } try { success = new SignUp().signup(email, name); } catch (SDKException ex) { LGR.log(Level.SEVERE, null, ex); } if (success) { JOptionPane.showMessageDialog(null, "Please check your email to confirm"); dispose(); return; } JOptionPane.showMessageDialog(null, "Error signing up"); } }); add(signUpPanel); pack(); setLocationRelativeTo(Main.frame); setVisible(true); }
From source file:NewFilterTable.java
public NewFilterTable() { setDefaultCloseOperation(EXIT_ON_CLOSE); String[] columns = { "ID", "Des", "Date", "Fixed" }; Object[][] rows = { { 1, "C", new Date(), new Date() }, { 2, "G", new Date(), new Date() }, { 5, "F", new Date(), new Date() } }; TableModel model = new DefaultTableModel(rows, columns); JTable table = new JTable(model); final TableRowSorter<TableModel> sorter; sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);// ww w . j av a 2 s . c om getContentPane().add(new JScrollPane(table)); JPanel pnl = new JPanel(); pnl.add(new JLabel("Filter expression:")); final JTextField txtFE = new JTextField(25); pnl.add(txtFE); JButton btnSetFE = new JButton("Set Filter Expression"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { String expr = txtFE.getText(); sorter.setRowFilter(RowFilter.regexFilter(expr)); sorter.setSortKeys(null); } }; btnSetFE.addActionListener(al); pnl.add(btnSetFE); getContentPane().add(pnl, BorderLayout.SOUTH); setSize(750, 150); setVisible(true); }
From source file:SpringCompactGrid.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//ww w .j ava2 s . c o m */ private static void createAndShowGUI() { JPanel panel = new JPanel(new SpringLayout()); int rows = 10; int cols = 10; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int anInt = (int) Math.pow(r, c); JTextField textField = new JTextField(Integer.toString(anInt)); panel.add(textField); } } //Lay out the panel. SpringUtilities.makeCompactGrid(panel, //parent rows, cols, 3, 3, //initX, initY 3, 3); //xPad, yPad //Create and set up the window. JFrame frame = new JFrame("SpringCompactGrid"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. panel.setOpaque(true); //content panes must be opaque frame.setContentPane(panel); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:SpringGrid.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */// ww w . jav a 2s . c o m private static void createAndShowGUI() { // Create the panel and populate it. JPanel panel = new JPanel(new SpringLayout()); for (int i = 0; i < 9; i++) { JTextField textField = new JTextField(Integer.toString(i)); // Make the 4th field extra big. if (i == 4) { textField.setText("This one is extra long."); } panel.add(textField); } // Lay out the panel. SpringUtilities.makeGrid(panel, 3, 3, // rows, cols 5, 5, // initialX, initialY 5, 5);// xPad, yPad // Create and set up the window. JFrame frame = new JFrame("SpringGrid"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the content pane. panel.setOpaque(true); // content panes must be opaque frame.setContentPane(panel); // Display the window. frame.pack(); frame.setVisible(true); }