private JTextField m_userInputTf = new JTextField(5); private JTextField m_totalTf = new JTextField(20); private JButton m_multiplyBtn = new JButton("Multiply"); private JButton m_clearBtn = new JButton("Clear"); m_totalTf.setText(m_model.getValue()); m_totalTf.setEditable(false); content.add(new JLabel("Input")); content.add(m_userInputTf); content.add(m_multiplyBtn); content.add(new JLabel("Total")); content.add(m_totalTf); this.pack(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_totalTf.setText(INITIAL_VALUE); m_totalTf.setText(newTotal);
private JTextField firstText = new JTextField("Desired TextField"); private JButton copyButton = new JButton("Copy text from JTextFields"); private CopyTextControl2 control; add(firstText); add(copyButton); firstText.setText(text);
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20)); final JTextField textField = new JTextField("Enter text here..."); textField.addMouseListener(new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e){ textField.setText(""); frame.add(textField); frame.pack(); frame.setVisible(true);
import javax.swing.*; public class CallApplet extends JApplet { JTextField output; public void init() { output = new JTextField(20); add(output); validate(); } public void setMessage(String message) { output.setText(message); } }
JFrame frame = new JFrame(); final JTextArea textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); textArea.setText("Something. Something else.\nA second line\na third line" + "Blabla\nBlabla\nBlabla\nBlabla\nBlabla\nBlabla\nBlabla\n" + "Blabla\nBlabla\nBlabla\nBlabla\nBlabla\nBlabla\nSomething. Samething else.\nA second line\na third line" + "Blabla\nBlabla\nBlabla\nBlabla\nBlabla\nBlabla\n"); textArea.setSelectionColor(Color.RED); frame.add(pane); frame.setSize(300, 120); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
import javax.swing.*; import java.awt.*; public class PreviewClass extends JPanel{ private JTextField namePreview; /** * @param namePreview the namePreview to set */ public void setNamePreview(String textContent) { this.namePreview.setText(textContent); } public PreviewClass() { setLayout(new FlowLayout()); namePreview=new JTextField(15); namePreview.setEditable(false); add(namePreview); } }
import java.awt.BorderLayout; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; class TextPanel extends JPanel { private JTextArea textarea = new JTextArea(20, 40); public TextPanel() { setLayout(new BorderLayout()); JScrollPane scrollPane = new JScrollPane(textarea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); add(scrollPane); } public JTextArea getTextarea() { return textarea; } public void clearText() { textarea.setText(""); } }
private final JFrame f = new JFrame(); private final JTextField tf = new JTextField(25); private final JTextArea ta = new JTextArea(15, 25); private final JButton send = new JButton("Send"); this.kind = kind; f.setTitle("Echo " + kind); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getRootPane().setDefaultButton(send); f.add(tf, BorderLayout.NORTH); f.add(new JScrollPane(ta), BorderLayout.CENTER); f.add(send, BorderLayout.SOUTH); f.setLocation(kind.offset, 300); f.pack(); send.addActionListener(this); ta.setLineWrap(true); f.setVisible(true); thread.start(); tf.setText("");
public Row(ActionListener l, String name, Object value) { setLayout(new LinearLayout()); _name = new JTextField(25); _name.addActionListener(l); add(_name); if (name != null) { _name.setText(name); _name.setEditable(false); } _value = new JTextField(25); _value.addActionListener(l); add(_value); // todo: support Lists better if (value instanceof List) { multi = true; _value.setText(Util.encodeCommaString((List)value)); } else if (value != null) { _value.setText(value.toString()); } }
/** * Method generated by IntelliJ IDEA GUI Designer * >>> IMPORTANT!! <<< * DO NOT edit this method OR call it in your code! * * @noinspection ALL */ private void $$$setupUI$$$() { settingsPanel = new JPanel(); settingsPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1)); final JScrollPane scrollPane1 = new JScrollPane(); scrollPane1.setVerticalScrollBarPolicy(22); settingsPanel.add(scrollPane1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); scrollPane1.setBorder(BorderFactory.createTitledBorder("List of valid commands:")); validCommandsEdit = new JTextArea(); validCommandsEdit.setText(""); validCommandsEdit.putClientProperty("html.disable", Boolean.TRUE); scrollPane1.setViewportView(validCommandsEdit); }
JFrame frame = new JFrame("WindowCommunication"); frame.getContentPane().add(new MyFramePanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); private JTextField field = new JTextField(10); private JButton openDialogeBtn = new JButton("Open Dialog"); field.setFocusable(false); add(field); add(openDialogeBtn); ModalityType.APPLICATION_MODAL); dialog.getContentPane().add(dialogPanel); dialog.pack(); dialog.setLocationRelativeTo(null); field.setText(dialogPanel.getFieldText()); private JTextField field = new JTextField(10); private JButton okButton = new JButton("OK");
import javax.swing.*; public class MyFrame extends JFrame { public MyFrame() { setBounds(100, 100, 491, 310); getContentPane().setLayout(null); JTextArea textField = new JTextArea(); textField.setEditable(false); String str = ""; for (int i = 0; i < 50; ++i) str += "Some text\n"; textField.setText(str); JScrollPane scroll = new JScrollPane(textField); scroll.setBounds(10, 11, 455, 249); // <-- THIS getContentPane().add(scroll); setLocationRelativeTo ( null ); } }
JTextArea ta = new JTextArea(); ta.setFont(font); ta.setText(fontText); ta.setEditable(false); JPanel fontNameCol = new JPanel(new GridLayout(0, 1, 2, 2)); JPanel fontExampleCol = new JPanel(new GridLayout(0, 1, 2, 2)); fontTable.add(fontNameCol, BorderLayout.WEST); fontTable.add(fontExampleCol, BorderLayout.CENTER); for (int ii = 0; ii < fonts.length; ii++) { fontNameCol.add(new JLabel(fonts[ii])); fontExampleCol.add(getExampleOfFont(fonts[ii])); p.add(tabPane, BorderLayout.CENTER); p.setPreferredSize(new Dimension(400, 400)); JFrame f = new JFrame("Properties"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.getContentPane().add(p, BorderLayout.CENTER); f.pack(); f.setMinimumSize(f.getPreferredSize()); f.setSize(600, 500); f.setLocationRelativeTo(null); f.setVisible(true);
import javax.swing.*; // JFrame, JPanel, ... import java.awt.*; // GridLayout public class RandomMatrix10x10 extends JFrame { // This is the window class public static class RandomNumber extends JPanel { // This is the random number grid space class public RandomNumber() { JTextArea area = new JTextArea(); // This will contain the number area.setText(Double.toString(Math.random())); // This puts the number in place area.setEditable(false); // This prevents the user from changing the matrix this.add(area); // This puts the number into the gridspace } } public RandomMatrix10x10() { this.setLayout(new GridLayout(10, 10)); // This makes the frame into a 10 x 10 grid for (int i = 0; i < 100; i++) { this.add(new RandomNumber()); // This puts all 100 numbers in place } } }
private WebEngine engine; private JFrame frame = new JFrame(); private JPanel panel = new JPanel(new BorderLayout()); private JLabel lblStatus = new JLabel(); private JTextField txtURL = new JTextField(); private JProgressBar progressBar = new JProgressBar(); topBar.add(txtURL, BorderLayout.CENTER); topBar.add(btnGo, BorderLayout.EAST); statusBar.add(lblStatus, BorderLayout.CENTER); statusBar.add(progressBar, BorderLayout.EAST); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { txtURL.setText(newValue); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true);
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JPanel bottomPanel = CreateBottomPanel(); frame = new JFrame("Comp Table Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(CompTableScrollpane, BorderLayout.CENTER); frame.add(bottomPanel, BorderLayout.SOUTH); frame.setPreferredSize(new Dimension(800, 400)); frame.setLocation(150, 150); frame.pack(); frame.setVisible(true); panel.add(addButton); return panel; private JComboBox typeCombo = new JComboBox(new Object[]{"height", "length", "volume"}); private JComboBox relationCombo = new JComboBox(new Object[]{"above", "below", "between"}); private JTextField lowerField = new JTextField(); private JLabel labelAnd = new JLabel(" and "); private JTextField upperField = new JTextField(); private JButton removeButton = new JButton("remove"); typeCombo.setSelectedIndex(Comp.type); relationCombo.setSelectedIndex(Comp.relation); lowerField.setText(Comp.lower); upperField.setText(Comp.upper); enableUpper(Comp.relation == 2);
unregisterListeners(); try { textfield.setText(""); textfield.setForeground(foregroundColor); } finally { unregisterListeners(); try { textfield.setText(ghostText); textfield.setForeground(ghostColor); } finally { JFrame frame = new JFrame("Test ghost text"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JTextField textField = new JTextField(); JButton button = new JButton("Grab focus"); GhostText ghostText = new GhostText(textField, "Please enter some text here..."); textField.setPreferredSize(new Dimension(300, 24)); panel.add(textField); panel.add(button); frame.add(panel); frame.pack(); frame.setVisible(true); button.grabFocus();
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField f = new JTextField(10); p.add(f); frame.add(p); frame.pack(); frame.setVisible(true); lastFocusableIndex = 0; sl.setFocused(false); autoSuggestionPopUpWindow.setVisible(false); setFocusToTextField(); autoSuggestionPopUpWindow.setVisible(false); setFocusToTextField(); suggestionsPanel.add(suggestionLabel); String t = text.substring(0, text.lastIndexOf(typedWord)); String tmp = t + text.substring(text.lastIndexOf(typedWord)).replace(typedWord, suggestedWord); textField.setText(tmp + " ");