List of usage examples for javax.swing JTextField JTextField
public JTextField(String text, int columns)
TextField
initialized with the specified text and columns. From source file:ChangeTrackingTest.java
public ColorFrame() { setTitle("ChangeTrackingTest"); DocumentListener listener = new DocumentListener() { public void insertUpdate(DocumentEvent event) { setColor();/*ww w .jav a 2s . c om*/ } public void removeUpdate(DocumentEvent event) { setColor(); } public void changedUpdate(DocumentEvent event) { } }; panel = new JPanel(); panel.add(new JLabel("Red:")); redField = new JTextField("255", 3); panel.add(redField); redField.getDocument().addDocumentListener(listener); panel.add(new JLabel("Green:")); greenField = new JTextField("255", 3); panel.add(greenField); greenField.getDocument().addDocumentListener(listener); panel.add(new JLabel("Blue:")); blueField = new JTextField("255", 3); panel.add(blueField); blueField.getDocument().addDocumentListener(listener); add(panel); pack(); }
From source file:dnd.TextCutPaste.java
public TextCutPaste() { super(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); //Create the transfer handler. TextTransferHandler th = new TextTransferHandler(); //Create some text fields. JPanel buttonPanel = new JPanel(new GridLayout(3, 1)); JTextField textField = new JTextField("Cut, copy and paste...", 30); textField.setTransferHandler(th);//www . j a v a 2s.com textField.setDragEnabled(true); buttonPanel.add(textField); textField = new JTextField("or drag and drop...", 30); textField.setTransferHandler(th); textField.setDragEnabled(true); buttonPanel.add(textField); textField = new JTextField("from any of these text fields.", 30); textField.setTransferHandler(th); textField.setDragEnabled(true); buttonPanel.add(textField); add(buttonPanel, BorderLayout.CENTER); }
From source file:layout.CardLayoutDemo.java
public void addComponentToPane(Container pane) { //Put the JComboBox in a JPanel to get a nicer look. JPanel comboBoxPane = new JPanel(); //use FlowLayout String comboBoxItems[] = { BUTTONPANEL, TEXTPANEL }; JComboBox cb = new JComboBox(comboBoxItems); cb.setEditable(false);/* ww w.j a v a 2 s . c o m*/ cb.addItemListener(this); comboBoxPane.add(cb); //Create the "cards". JPanel card1 = new JPanel(); card1.add(new JButton("Button 1")); card1.add(new JButton("Button 2")); card1.add(new JButton("Button 3")); JPanel card2 = new JPanel(); card2.add(new JTextField("TextField", 20)); //Create the panel that contains the "cards". cards = new JPanel(new CardLayout()); cards.add(card1, BUTTONPANEL); cards.add(card2, TEXTPANEL); pane.add(comboBoxPane, BorderLayout.PAGE_START); pane.add(cards, BorderLayout.CENTER); }
From source file:layout.TabDemo.java
public void addComponentToPane(Container pane) { JTabbedPane tabbedPane = new JTabbedPane(); //Create the "cards". JPanel card1 = new JPanel() { //Make the panel wider than it really needs, so //the window's wide enough for the tabs to stay //in one row. public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); size.width += extraWindowWidth; return size; }//from w w w . ja va 2 s. co m }; card1.add(new JButton("Button 1")); card1.add(new JButton("Button 2")); card1.add(new JButton("Button 3")); JPanel card2 = new JPanel(); card2.add(new JTextField("TextField", 20)); tabbedPane.addTab(BUTTONPANEL, card1); tabbedPane.addTab(TEXTPANEL, card2); pane.add(tabbedPane, BorderLayout.CENTER); }
From source file:com.emental.mindraider.ui.dialogs.ConnectUriqaServerJDialog.java
/** * Constructor.//from w w w . j av a 2 s . c o m */ public ConnectUriqaServerJDialog() { super(Messages.getString("ConnectUriqaServerJDialog.title")); getContentPane().setLayout(new BorderLayout()); // north JPanel north = new JPanel(); north.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.serverUrl"))); uriqaServerUrl = new JTextField("http://sw.nokia.com/uriqa/", 31); uriqaServerUrl.setMinimumSize(new Dimension(TEXT_AREAS_WIDTH, uriqaServerUrl.getPreferredSize().height)); uriqaServerUrl.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) { connect(); } } public void keyReleased(KeyEvent keyEvent) { } public void keyTyped(KeyEvent keyEvent) { } }); north.add(uriqaServerUrl); getContentPane().add(north, BorderLayout.NORTH); // center JPanel center = new JPanel(); center.setLayout(new BorderLayout()); JPanel centerTop = new JPanel(); centerTop.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.resource"))); String[] knowUriqaUris = new String[] { "http://sw.nokia.com/VOC-1/term", "http://sw.nokia.com/MARS-3/Rank", "http://sw.nokia.com/MARS-3", "http://sw.nokia.com/schemas/nokia/MARS-3.1.rdf" }; resourceUri = new JComboBox(knowUriqaUris); resourceUri.setMinimumSize(new Dimension(TEXT_AREAS_WIDTH, resourceUri.getPreferredSize().height)); resourceUri.setEditable(true); centerTop.add(resourceUri); JPanel centerCenter = new JPanel(); centerCenter.setLayout(new FlowLayout(FlowLayout.LEFT)); centerCenter.setToolTipText(Messages.getString("ConnectUriqaServerJDialog.loadOverToolTip")); centerCenter.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.loadOver"))); JCheckBox loadOver = new JCheckBox(); loadOver.setSelected(true); loadOver.setEnabled(false); centerCenter.add(loadOver); JPanel centerBottom = new JPanel(); centerBottom.setLayout(new FlowLayout(FlowLayout.LEFT)); centerBottom.setToolTipText(Messages.getString("ConnectUriqaServerJDialog.addInferedToolTip")); centerBottom.add(new JLabel(Messages.getString("ConnectUriqaServerJDialog.addInfered"))); addInfered = new JCheckBox(); addInfered.setSelected(true); centerBottom.add(addInfered); center.add(centerTop, BorderLayout.NORTH); center.add(centerCenter, BorderLayout.CENTER); center.add(centerBottom, BorderLayout.SOUTH); getContentPane().add(center, BorderLayout.CENTER); // south JPanel south = new JPanel(); JButton uploadButton = new JButton(Messages.getString("ConnectUriqaServerJDialog.connect")); uploadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { connect(); } }); south.add(uploadButton); JButton cancelButton = new JButton(Messages.getString("ConnectUriqaServerJDialog.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); south.add(cancelButton); getContentPane().add(south, BorderLayout.SOUTH); // show pack(); Gfx.centerAndShowWindow(this); }
From source file:TextCutPaste.java
public TextCutPaste() { super(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); // Create the transfer handler. TextTransferHandler th = new TextTransferHandler(); // Create some text fields. JPanel buttonPanel = new JPanel(new GridLayout(3, 1)); JTextField textField = new JTextField("Cut, copy and paste...", 30); textField.setTransferHandler(th);/*from w w w . j a va2 s . c o m*/ textField.setDragEnabled(true); buttonPanel.add(textField); textField = new JTextField("or drag and drop...", 30); textField.setTransferHandler(th); textField.setDragEnabled(true); buttonPanel.add(textField); textField = new JTextField("from any of these text fields.", 30); textField.setTransferHandler(th); textField.setDragEnabled(true); buttonPanel.add(textField); add(buttonPanel, BorderLayout.CENTER); }
From source file:MenuItemChooser.java
private void initGUI() { JPanel itemDetailsPanel = new JPanel(); itemDetailsPanel.setLayout(new GridLayout(4, 2)); itemDetailsPanel.setBackground(Color.WHITE); JLabel lbl = new JLabel("Item: "); itemDetailsPanel.add(lbl);/*from w ww.ja v a2 s . c om*/ itemName = new JLabel(""); itemDetailsPanel.add(itemName); lbl = new JLabel("Type: "); itemDetailsPanel.add(lbl); itemType = new JLabel(""); itemDetailsPanel.add(itemType); lbl = new JLabel("Price: $ "); itemDetailsPanel.add(lbl); price = new JLabel(""); itemDetailsPanel.add(price); lbl = new JLabel("Quantity: "); itemDetailsPanel.add(lbl); qty = new JTextField("0", 1); qty.addActionListener(this); qty.addFocusListener(this); itemDetailsPanel.add(qty); JPanel imgDescPanel = new JPanel(new BorderLayout()); imgDescPanel.setBackground(Color.WHITE); image = new JLabel(""); image.setHorizontalAlignment(SwingConstants.CENTER); image.setVerticalAlignment(SwingConstants.CENTER); imgDescPanel.add(image, BorderLayout.NORTH); desc = new JLabel("desc"); imgDescPanel.add(desc, BorderLayout.SOUTH); JPanel buttonPanel = new JPanel(); buttonPanel.setBackground(Color.WHITE); next = new JButton("Next"); next.addActionListener(this); buttonPanel.add(next); prev = new JButton("Previous"); prev.addActionListener(this); buttonPanel.add(prev); order = new JButton("Order"); order.addActionListener(this); buttonPanel.add(order); cancel = new JButton("Cancel / New"); cancel.addActionListener(this); buttonPanel.add(cancel); close = new JButton("Close"); close.addActionListener(this); close.setEnabled(false); buttonPanel.add(close); totalLbl = new JLabel(""); totalLbl.setFont(new Font("Serif", Font.BOLD, 14)); totalLbl.setForeground((Color.GREEN).darker()); buttonPanel.add(totalLbl); BorderLayout bl = new BorderLayout(); bl.setHgap(30); bl.setVgap(20); setLayout(bl); setBackground(Color.WHITE); add(itemDetailsPanel, BorderLayout.WEST); add(imgDescPanel, BorderLayout.EAST); add(buttonPanel, BorderLayout.SOUTH); TitledBorder title = BorderFactory.createTitledBorder("Choose Menu Items And Place Order"); setBorder(title); loadMenuItem(); }
From source file:FontPicker.java
public FontChooser(Frame parent) { super(parent, "Font Chooser", true); setSize(450, 450);/*from w w w . jav a 2 s. c o m*/ attributes = new SimpleAttributeSet(); // Make sure that any way the user cancels the window does the right // thing addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { closeAndCancel(); } }); // Start the long process of setting up our interface Container c = getContentPane(); JPanel fontPanel = new JPanel(); fontName = new JComboBox(new String[] { "TimesRoman", "Helvetica", "Courier" }); fontName.setSelectedIndex(1); fontName.addActionListener(this); fontSize = new JTextField("12", 4); fontSize.setHorizontalAlignment(SwingConstants.RIGHT); fontSize.addActionListener(this); fontBold = new JCheckBox("Bold"); fontBold.setSelected(true); fontBold.addActionListener(this); fontItalic = new JCheckBox("Italic"); fontItalic.addActionListener(this); fontPanel.add(fontName); fontPanel.add(new JLabel(" Size: ")); fontPanel.add(fontSize); fontPanel.add(fontBold); fontPanel.add(fontItalic); c.add(fontPanel, BorderLayout.NORTH); // Set up the color chooser panel and attach a change listener so that // color // updates get reflected in our preview label. colorChooser = new JColorChooser(Color.black); colorChooser.getSelectionModel().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { updatePreviewColor(); } }); c.add(colorChooser, BorderLayout.CENTER); JPanel previewPanel = new JPanel(new BorderLayout()); previewLabel = new JLabel("Here's a sample of this font."); previewLabel.setForeground(colorChooser.getColor()); previewPanel.add(previewLabel, BorderLayout.CENTER); // Add in the Ok and Cancel buttons for our dialog box JButton okButton = new JButton("Ok"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { closeAndSave(); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { closeAndCancel(); } }); JPanel controlPanel = new JPanel(); controlPanel.add(okButton); controlPanel.add(cancelButton); previewPanel.add(controlPanel, BorderLayout.SOUTH); // Give the preview label room to grow. previewPanel.setMinimumSize(new Dimension(100, 100)); previewPanel.setPreferredSize(new Dimension(100, 100)); c.add(previewPanel, BorderLayout.SOUTH); }