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:MainClass.java
public MainClass() { final JTree tree; final JTextField jtf; DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options"); DefaultMutableTreeNode a = new DefaultMutableTreeNode("A"); top.add(a);//w w w. j av a 2 s. co m DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1"); a.add(a1); DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2"); a.add(a2); DefaultMutableTreeNode b = new DefaultMutableTreeNode("B"); top.add(b); DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1"); b.add(b1); DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2"); b.add(b2); DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3"); b.add(b3); tree = new JTree(top); JScrollPane jsp = new JScrollPane(tree); add(jsp, BorderLayout.CENTER); jtf = new JTextField("", 20); add(jtf, BorderLayout.SOUTH); tree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { TreePath tp = tree.getPathForLocation(me.getX(), me.getY()); if (tp != null) jtf.setText(tp.toString()); else jtf.setText(""); } }); }
From source file:layout.SpringDemo1.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//from w w w . j av a 2 s. co m */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); contentPane.add(new JLabel("Label: ")); contentPane.add(new JTextField("Text field", 15)); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:layout.SpringDemo2.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from ww w.j a v a 2s . c o m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:layout.SpringDemo3.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*w ww. j ava2 s. c o m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo3"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the content pane: Its right //edge should be 5 pixels beyond the text field's right //edge, and its bottom edge should be 5 pixels beyond //the bottom edge of the tallest component (which we'll //assume is textField). layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, textField); layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, textField); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:layout.SpringDemo4.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//from www . j a v a 2s . co m */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo4"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). SpringLayout.Constraints labelCons = layout.getConstraints(label); labelCons.setX(Spring.constant(5)); labelCons.setY(Spring.constant(5)); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). SpringLayout.Constraints textFieldCons = layout.getConstraints(textField); textFieldCons.setX(Spring.sum(Spring.constant(5), labelCons.getConstraint(SpringLayout.EAST))); textFieldCons.setY(Spring.constant(5)); //Adjust constraints for the content pane. setContainerSize(contentPane, 5); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:ColorComposite.java
public ColorComposite() { super();/* w w w . j av a 2s . co m*/ Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); JPanel panel = new JPanel(); JLabel label = new JLabel("Color-Composite: "); JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 65); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider tempSlider = (JSlider) e.getSource(); alphaValue = (float) (tempSlider.getValue() / 100.0); textField.setText(Float.toString(alphaValue)); canvas.repaint(); } }); textField = new JTextField("0.65", 4); panel.add(label); panel.add(slider); panel.add(textField); container.add(BorderLayout.SOUTH, panel); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(450, 450); setVisible(true); }
From source file:SpringDemo1.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */// w ww. j a v a2s . c om private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("SpringDemo1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); contentPane.add(new JLabel("Label: ")); contentPane.add(new JTextField("Text field", 15)); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:SpringDemo2.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//* ww w .j a va 2s . c o m*/ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("SpringDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:SpringDemo3.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//* w w w. j ava2s. co m*/ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("SpringDemo3"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the content pane: Its right //edge should be 5 pixels beyond the text field's right //edge, and its bottom edge should be 5 pixels beyond //the bottom edge of the tallest component (which we'll //assume is textField). layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, textField); layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, textField); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:SpringDemo4.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//*from w w w . ja v a 2 s . co m*/ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("SpringDemo4"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). SpringLayout.Constraints labelCons = layout.getConstraints(label); labelCons.setX(Spring.constant(5)); labelCons.setY(Spring.constant(5)); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). SpringLayout.Constraints textFieldCons = layout.getConstraints(textField); textFieldCons.setX(Spring.sum(Spring.constant(5), labelCons.getConstraint(SpringLayout.EAST))); textFieldCons.setY(Spring.constant(5)); //Adjust constraints for the content pane. setContainerSize(contentPane, 5); //Display the window. frame.pack(); frame.setVisible(true); }