Java Code Examples for javax.swing.JTextField#addActionListener()

The following examples show how to use javax.swing.JTextField#addActionListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeSearch.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private void createToolBar() {
    searchBar = new JToolBar();
    searchBar.setFloatable(false);
    searchBar.setLayout(new BoxLayout(searchBar, BoxLayout.X_AXIS));
    searchBar.setBorder(BorderFactory.createEtchedBorder());

    JLabel searchLabel = new JLabel(Utils.getIconByResourceName("/ui/resources/search"));

    searchField = new JTextField();
    searchField.setActionCommand("SearchField");
    searchField.addActionListener(this);

    searchBar.add(searchLabel);
    searchBar.add(new javax.swing.Box.Filler(new java.awt.Dimension(5, 0),
            new java.awt.Dimension(5, 0),
            new java.awt.Dimension(5, 32767)));
    searchBar.add(searchField);

}
 
Example 2
Source File: CustomSettingsDialog.java    From swingsane with Apache License 2.0 6 votes vote down vote up
public CustomTableCellEditor(JTextField textField, final OptionsOrderValuePair vp) {
  super(textField);
  textField.removeActionListener(delegate);
  valuePair = vp;
  delegate.setValue(textField);
  delegate = new EditorDelegate() {
    @Override
    public void setValue(Object val) {
      if (val instanceof JTextField) {
        if (value == null) {
          value = val;
        }
      }
    }

    @Override
    public boolean stopCellEditing() {
      updateOption(valuePair, (Component) value);
      return true;
    }
  };
  textField.addActionListener(delegate);
  setClickCountToStart(1);
}
 
Example 3
Source File: InitalSettings.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
private JPanel FilesPanel() {
	JPanel northpanel = new JPanel();
	//JPanel northcolumnpanel = addColumn(northpanel);
	//txtLogFileDirectory = addSettingsRow(northpanel, 20, "Log files directory", Config.logFileDirectory);
	//JPanel panel = new JPanel();
	//northpanel.add(panel);
	northpanel.setLayout(new BorderLayout());
	
	JLabel lblDisplayModuleFont = new JLabel("Log files directory");
	lblDisplayModuleFont.setBorder(new EmptyBorder(5, 2, 5, 5) );
	northpanel.add(lblDisplayModuleFont, BorderLayout.WEST);
	txtLogFileDirectory = new JTextField(Config.logFileDirectory);
	northpanel.add(txtLogFileDirectory, BorderLayout.CENTER);
	txtLogFileDirectory.setColumns(30);
	
	txtLogFileDirectory.addActionListener(this);

	btnBrowse = new JButton("Browse");
	btnBrowse.addActionListener(this);
	northpanel.add(btnBrowse, BorderLayout.EAST);
	//TitledBorder title = new TitledBorder(null, "Files and Directories", TitledBorder.LEADING, TitledBorder.TOP, null, null);
	//title.setTitleFont(new Font("SansSerif", Font.BOLD, 14));
	//northpanel.setBorder(title);
	
	return northpanel;

}
 
Example 4
Source File: ResultSetTableCellEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ResultSetTableCellEditor(final JTextField textField) {
    super(textField);
    delegate = new EditorDelegate() {

        @Override
        public void setValue(Object value) {
            val = value;
            textField.setText((value != null) ? value.toString() : "");
        }

        @Override
        public boolean isCellEditable(EventObject evt) {
            if (evt instanceof MouseEvent) {
                return ((MouseEvent) evt).getClickCount() >= 2;
            }
            return true;
        }

        @Override
        public Object getCellEditorValue() {
            String txtVal = textField.getText();
            if (val == null && txtVal.equals("")) {
                return null;
            } else {
                    return txtVal;
                }
            }
    };

    textField.addActionListener(delegate);
    // #204176 - workarround for MacOS L&F
    textField.setCaret(new DefaultCaret());
}
 
Example 5
Source File: GUIFrame.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
private void addSnapToGridField(JToolBar buttonBar, Insets margin) {

		gridSpacing = new JTextField("1000000 m") {
			@Override
			protected void processFocusEvent(FocusEvent fe) {
				if (fe.getID() == FocusEvent.FOCUS_LOST) {
					GUIFrame.this.setSnapGridSpacing(this.getText().trim());
				}
				else if (fe.getID() == FocusEvent.FOCUS_GAINED) {
					gridSpacing.selectAll();
				}
				super.processFocusEvent( fe );
			}
		};

		gridSpacing.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				GUIFrame.this.setSnapGridSpacing(gridSpacing.getText().trim());
				controlStartResume.requestFocusInWindow();
			}
		});

		gridSpacing.setMaximumSize(gridSpacing.getPreferredSize());
		int hght = snapToGrid.getPreferredSize().height;
		gridSpacing.setPreferredSize(new Dimension(gridSpacing.getPreferredSize().width, hght));

		gridSpacing.setHorizontalAlignment(JTextField.RIGHT);
		gridSpacing.setToolTipText(formatToolTip("Snap Grid Spacing",
				"Distance between adjacent grid points, e.g. 0.1 m, 10 km, etc."));

		gridSpacing.setEnabled(snapToGrid.isSelected());

		buttonBar.add(gridSpacing);
	}
 
Example 6
Source File: Query.java    From opt4j with MIT License 5 votes vote down vote up
public QueryColorChooser(String name, String defaultColor) {
	super(BoxLayout.X_AXIS);
	// _defaultColor = defaultColor;
	_entryBox = new JTextField(defaultColor, _width);

	JButton button = new JButton("Choose");
	button.addActionListener(this);
	add(_entryBox);
	add(button);

	// Add the listener last so that there is no notification
	// of the first value.
	_entryBox.addActionListener(new QueryActionListener(name));

	// Add a listener for loss of focus. When the entry gains
	// and then loses focus, listeners are notified of an update,
	// but only if the value has changed since the last notification.
	// FIXME: Unfortunately, Java calls this listener some random
	// time after the window has been closed. It is not even a
	// a queued event when the window is closed. Thus, we have
	// a subtle bug where if you enter a value in a line, do not
	// hit return, and then click on the X to close the window,
	// the value is restored to the original, and then sometime
	// later, the focus is lost and the entered value becomes
	// the value of the parameter. I don't know of any workaround.
	_entryBox.addFocusListener(new QueryFocusListener(name));

	_name = name;
}
 
Example 7
Source File: SkillEditor.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private JTextField createField(Container labelParent, Container fieldParent, String title, String text, String tooltip, int maxChars) {
    JTextField field = new JTextField(maxChars > 0 ? Text.makeFiller(maxChars, 'M') : text);
    if (maxChars > 0) {
        UIUtilities.setToPreferredSizeOnly(field);
        field.setText(text);
    }
    field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    field.setEnabled(mIsEditable);
    labelParent.add(new LinkedLabel(title, field));
    fieldParent.add(field);
    field.addActionListener(this);
    field.addFocusListener(this);
    return field;
}
 
Example 8
Source File: Query.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public QueryColorChooser(
    String name,
    String defaultColor) {

    super(BoxLayout.X_AXIS);
    _defaultColor = defaultColor;
    _entryBox = new JTextField(defaultColor, _width);
    JButton button = new JButton("Choose");
    button.addActionListener(this);
    add(_entryBox);
    add(button);
    // Add the listener last so that there is no notification
    // of the first value.
    _entryBox.addActionListener(new QueryActionListener(name));

    // Add a listener for loss of focus.  When the entry gains
    // and then loses focus, listeners are notified of an update,
    // but only if the value has changed since the last notification.
    // FIXME: Unfortunately, Java calls this listener some random
    // time after the window has been closed.  It is not even a
    // a queued event when the window is closed.  Thus, we have
    // a subtle bug where if you enter a value in a line, do not
    // hit return, and then click on the X to close the window,
    // the value is restored to the original, and then sometime
    // later, the focus is lost and the entered value becomes
    // the value of the parameter.  I don't know of any workaround.
    _entryBox.addFocusListener(new QueryFocusListener(name));

    _name = name;
}
 
Example 9
Source File: EquipmentEditor.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private JTextField createIntegerNumberField(Container labelParent, Container fieldParent, String title, int value, String tooltip, int maxDigits) {
    JTextField field = new JTextField(Text.makeFiller(maxDigits, '9') + Text.makeFiller(maxDigits / 3, ','));
    UIUtilities.setToPreferredSizeOnly(field);
    field.setText(Numbers.format(value));
    field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    field.setEnabled(mIsEditable);
    new NumberFilter(field, false, false, true, maxDigits);
    field.addActionListener(this);
    field.addFocusListener(this);
    labelParent.add(new LinkedLabel(title, field));
    fieldParent.add(field);
    return field;
}
 
Example 10
Source File: JSpinField.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * JSpinField constructor with given minimum and maximum vaues and initial
 * value 0.
 */
public JSpinField(int min, int max) {
	super();
	setName("JSpinField");
	this.min = min;
	if (max < min)
		max = min;
	this.max = max;
	value = 0;
	if (value < min)
		value = min;
	if (value > max)
		value = max;

	darkGreen = new Color(0, 150, 0);
	setLayout(new BorderLayout());
	textField = new JTextField();
	textField.addCaretListener(this);
	textField.addActionListener(this);
	textField.setHorizontalAlignment(SwingConstants.RIGHT);
	textField.setBorder(BorderFactory.createEmptyBorder());
	textField.setText(Integer.toString(value));
	textField.addFocusListener(this);
	spinner = new JSpinner() {
		private static final long serialVersionUID = -6287709243342021172L;
		private JTextField textField = new JTextField();

		public Dimension getPreferredSize() {
			Dimension size = super.getPreferredSize();
			return new Dimension(size.width, textField.getPreferredSize().height);
		}
	};
	spinner.setEditor(textField);
	spinner.addChangeListener(this);
	// spinner.setSize(spinner.getWidth(), textField.getHeight());
	add(spinner, BorderLayout.CENTER);
}
 
Example 11
Source File: RTSPTest.java    From RTSPTest with MIT License 4 votes vote down vote up
public RTSPTest() {
	// Set up our GUI elements
	mainFrame = new JFrame("RTSP Test");

	setupButton = new JButton("Setup");
	playButton = new JButton("Play");
	pauseButton = new JButton("Pause");
	optionsButton = new JButton("Options");
	describeButton = new JButton("Describe");
	teardownButton = new JButton("Teardown");
	textField = new JTextField("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov");

	buttonPanel = new JPanel();
	textPanel = new JPanel();
	mainPanel = new JPanel();

	// Set up buttons
	buttonPanel.setLayout(new GridLayout(1,0));
	buttonPanel.add(describeButton);
	buttonPanel.add(optionsButton);
	buttonPanel.add(setupButton);
	buttonPanel.add(playButton);
	buttonPanel.add(pauseButton);
	buttonPanel.add(teardownButton);

	setupButton.addActionListener(this);
	playButton.addActionListener(this);
	pauseButton.addActionListener(this);
	optionsButton.addActionListener(this);
	describeButton.addActionListener(this);
	teardownButton.addActionListener(this);
	textField.addActionListener(this);

	// Set up text field
	textPanel.setLayout(new GridLayout(1,0));
	textPanel.add(textField);

	// Set main panel
	mainPanel.setLayout(null);
	mainPanel.add(textPanel);
	mainPanel.add(buttonPanel);
	textPanel.setBounds(0, 0, 450, 25);
	buttonPanel.setBounds(0, 25, 450, 50);

	// Add listener so that we quit we close the window
    mainFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
        	// Teardown the connection when we close the window
        	if (rtspControl != null) {
        		rtspControl.RTSPTeardown();
        		rtspControl.resetParameters(); // Just in case
        	}
        	System.exit(0);
        }
     });

	// Set up connection to default RTSP url before we even show GUI
	//hostName = "184.72.239.149";
	//portNumber = 554;
	//videoFile = "vod/mp4:BigBuckBunny_115k.mov";
	//rtspControl = new RTSPControl(hostName, portNumber, videoFile);

	// Create frame and show
	mainFrame.getContentPane().add(mainPanel, BorderLayout.CENTER);
	mainFrame.setSize(new Dimension(450, 100));
	mainFrame.setVisible(true);
}
 
Example 12
Source File: CustomDialog.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
/** Creates the reusable dialog. */
public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) {
    super(aFrame, true);
    dd = parent;

    magicWord = aWord.toUpperCase();
    setTitle("Quiz");

    textField = new JTextField(10);

    // Create an array of the text and components to be displayed.
    String msgString1 = "What was Dr. SEUSS's real last name?";
    String msgString2 = "(The answer is \"" + magicWord + "\".)";
    Object[] array = { msgString1, msgString2, textField };

    // Create an array specifying the number of dialog buttons
    // and their text.
    Object[] options = { btnString1, btnString2 };

    // Create the JOptionPane.
    optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]);

    // Make this dialog display it.
    setContentPane(optionPane);

    // Handle window closing correctly.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            /*
             * Instead of directly closing the window, we're going to change
             * the JOptionPane's value property.
             */
            optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
        }
    });

    // Ensure the text field always gets the first focus.
    addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent ce) {
            textField.requestFocusInWindow();
        }
    });

    // Register an event handler that puts the text into the option pane.
    textField.addActionListener(this);

    // Register an event handler that reacts to option pane state changes.
    optionPane.addPropertyChangeListener(this);
}
 
Example 13
Source File: Display3DGUI.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
static private final JPanel newPanelFilterableTable(final Image3DUniverse univ) {
	final JPanel p = new JPanel();
	p.setBackground(Color.white);
	final GridBagConstraints c = new GridBagConstraints();
	final GridBagLayout gb = new GridBagLayout();
	p.setLayout(gb);

	c.anchor = GridBagConstraints.NORTHWEST;
	c.fill = GridBagConstraints.HORIZONTAL;

	final JLabel label = new JLabel("RegEx: ");
	final JTextField regexField = new JTextField();
	final ContentTable table = new ContentTable(univ);
	final ContentTableModel ctm = new ContentTableModel(univ, regexField);
	table.setModel(ctm);
	univ.addUniverseListener(new TableUniverseListener(table));

	regexField.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(final ActionEvent e) {
			ctm.update(table);
		}
	});

	gb.setConstraints(label, c);
	p.add(label);

	c.gridx = 1;
	c.weightx = 1;
	gb.setConstraints(regexField, c);
	p.add(regexField);

	c.gridx = 0;
	c.gridy = 1;
	c.gridwidth = 2;
	c.weighty = 1;
	c.fill = GridBagConstraints.BOTH;
	final JScrollPane jsp = new JScrollPane(table);
	gb.setConstraints(jsp, c);
	p.add(jsp);

	addTitledLineBorder(p, "Contents");
	return p;
}
 
Example 14
Source File: Solver.java    From algorithms-nutshell-2ed with MIT License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	
	// solution found. Create GUI. 
	final JFrame frame = new JFrame();
	frame.setAlwaysOnTop(true);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.addWindowListener(new WindowAdapter() {

		/** Once opened: load up the images. */
		public void windowOpened(WindowEvent e) {
			System.out.println("Loading card images...");
			cardImages = CardImagesLoader.getDeck(e.getWindow());
		}
	});
	
	frame.setSize(808,350);
	JList<IMove> list = new JList<IMove>();
	
    // add widgets at proper location
    frame.setLayout(null);
    
    // top row:
    JPanel topLeft = new JPanel();
    topLeft.setBounds(0, 0, 400, 40);
    topLeft.add(new JLabel("Select Game:"));
    final JTextField jtf = new JTextField (7);
    topLeft.add(jtf);
    frame.add(topLeft);
    
    JPanel topRight = new JPanel();
    topRight.setBounds(400, 0, 400, 40);
    String instructions = "Select moves from below list to see game state at that moment.";
    topRight.add(new JLabel(instructions));
    frame.add(topRight);
    
    // bottom row
    FreeCellDrawing drawer = new FreeCellDrawing();
    drawer.setBounds (0, 40, 400, 275);
    drawer.setBackground(new java.awt.Color (0,128,0));
    frame.add(drawer);
    
    // Create the GUI and put it in the window with scrollbars.
	JScrollPane scrollingPane = new JScrollPane(list);
    scrollingPane.setAutoscrolls(true);
    scrollingPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollingPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    
    scrollingPane.setBounds(400, 40, 400, 275);
    frame.add(scrollingPane);
   
    // set up listeners and show everything
    jtf.addActionListener(new DealController(frame, drawer, list));	    
    frame.setVisible(true);
}
 
Example 15
Source File: MimicLogic.java    From raccoon4 with Apache License 2.0 4 votes vote down vote up
@Override
protected JPanel assemble() {
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

	gsfId = new JTextField(20);
	gsfId.setMargin(new Insets(2, 2, 2, 2));
	userAgent = new JTextField(20);
	userAgent.setMargin(new Insets(2, 2, 2, 2));
	HyperTextPane about = new HyperTextPane(
			Messages.getString("ExistingLogic.about")).withWidth(500)
			.withTransparency();
	gsfId.addActionListener(this);
	userAgent.addActionListener(this);
	gsfId.addCaretListener(this);
	userAgent.addCaretListener(this);

	GridBagConstraints gbc = new GridBagConstraints();
	JPanel container = new JPanel();
	container.setLayout(new GridBagLayout());
	gbc.gridx = 0;
	gbc.gridy = 0;
	gbc.anchor = GridBagConstraints.WEST;
	gbc.insets.left = 5;
	gbc.insets.bottom = 3;
	container.add(new JLabel(Messages.getString("ExistingLogic.gsfid")), gbc);

	gbc.gridx = 1;
	gbc.gridy = 0;
	container.add(gsfId, gbc);

	gbc.gridx = 0;
	gbc.gridy = 1;
	container.add(new JLabel(Messages.getString("ExistingLogic.useragent")),
			gbc);

	gbc.gridx = 1;
	gbc.gridy = 1;
	container.add(userAgent, gbc);

	panel.add(about);
	panel.add(Box.createVerticalStrut(20));
	panel.add(container);
	panel.add(Box.createVerticalStrut(20));

	return panel;
}
 
Example 16
Source File: AquaticFormFrame.java    From JavaMainRepo with Apache License 2.0 4 votes vote down vote up
public AquaticFormFrame(String title) {
	super(title);

	contentPanel.setLayout(new GridLayout(0, 3, 0, 0));

	JPanel panel = new JPanel();
	contentPanel.add(panel);

	JPanel pan = new JPanel();
	contentPanel.add(pan);

	SpringLayout slPanel = new SpringLayout();
	pan.setLayout(slPanel);

	nameLabel = new JLabel("Name: ");
	slPanel.putConstraint(SpringLayout.NORTH, nameLabel, 65, SpringLayout.NORTH, pan);
	slPanel.putConstraint(SpringLayout.WEST, nameLabel, 93, SpringLayout.WEST, pan);
	pan.add(nameLabel);

	swimLabel = new JLabel("Avgerage swim depth: ");
	slPanel.putConstraint(SpringLayout.NORTH, swimLabel, 100, SpringLayout.NORTH, pan);
	slPanel.putConstraint(SpringLayout.WEST, swimLabel, 93, SpringLayout.WEST, pan);
	pan.add(swimLabel);

	dangerPercLabel = new JLabel("Danger percentage: ");
	slPanel.putConstraint(SpringLayout.NORTH, dangerPercLabel, 135, SpringLayout.NORTH, pan);
	slPanel.putConstraint(SpringLayout.WEST, dangerPercLabel, 93, SpringLayout.WEST, pan);
	pan.add(dangerPercLabel);

	legsLabel = new JLabel("Number of legs: ");
	slPanel.putConstraint(SpringLayout.NORTH, legsLabel, 170, SpringLayout.NORTH, pan);
	slPanel.putConstraint(SpringLayout.WEST, legsLabel, 93, SpringLayout.WEST, pan);
	pan.add(legsLabel);

	maintCostLabel = new JLabel("Maintenance cost: ");
	slPanel.putConstraint(SpringLayout.NORTH, maintCostLabel, 205, SpringLayout.NORTH, pan);
	slPanel.putConstraint(SpringLayout.WEST, maintCostLabel, 93, SpringLayout.WEST, pan);
	pan.add(maintCostLabel);

	takenCareOfLabel = new JLabel("Taken care of: ");
	slPanel.putConstraint(SpringLayout.NORTH, takenCareOfLabel, 240, SpringLayout.NORTH, pan);
	slPanel.putConstraint(SpringLayout.WEST, takenCareOfLabel, 93, SpringLayout.WEST, pan);
	pan.add(takenCareOfLabel);

	isDangerousLabel = new JLabel("Is dangerous: ");
	slPanel.putConstraint(SpringLayout.NORTH, isDangerousLabel, 275, SpringLayout.NORTH, pan);
	slPanel.putConstraint(SpringLayout.WEST, isDangerousLabel, 93, SpringLayout.WEST, pan);
	pan.add(isDangerousLabel);

	JPanel rightPanel = new JPanel();
	contentPanel.add(rightPanel);
	setVisible(true);

	rightPanel.setLayout(slPanel);

	nameField = new JTextField(10);
	slPanel.putConstraint(SpringLayout.NORTH, nameField, 65, SpringLayout.NORTH, rightPanel);
	slPanel.putConstraint(SpringLayout.WEST, nameField, 93, SpringLayout.WEST, rightPanel);
	rightPanel.add(nameField);

	swimField = new JTextField(10);
	slPanel.putConstraint(SpringLayout.NORTH, swimField, 100, SpringLayout.NORTH, rightPanel);
	slPanel.putConstraint(SpringLayout.WEST, swimField, 93, SpringLayout.WEST, rightPanel);
	rightPanel.add(swimField);

	dangerPercField = new JTextField(10);
	slPanel.putConstraint(SpringLayout.NORTH, dangerPercField, 135, SpringLayout.NORTH, rightPanel);
	slPanel.putConstraint(SpringLayout.WEST, dangerPercField, 93, SpringLayout.WEST, rightPanel);
	rightPanel.add(dangerPercField);

	legsField = new JTextField(10);
	slPanel.putConstraint(SpringLayout.NORTH, legsField, 170, SpringLayout.NORTH, rightPanel);
	slPanel.putConstraint(SpringLayout.WEST, legsField, 93, SpringLayout.WEST, rightPanel);
	rightPanel.add(legsField);

	maintCostField = new JTextField(10);
	slPanel.putConstraint(SpringLayout.NORTH, maintCostField, 205, SpringLayout.NORTH, rightPanel);
	slPanel.putConstraint(SpringLayout.WEST, maintCostField, 93, SpringLayout.WEST, rightPanel);
	rightPanel.add(maintCostField);

	takenCareOfField = new JTextField(10);
	slPanel.putConstraint(SpringLayout.NORTH, takenCareOfField, 240, SpringLayout.NORTH, rightPanel);
	slPanel.putConstraint(SpringLayout.WEST, takenCareOfField, 93, SpringLayout.WEST, rightPanel);
	rightPanel.add(takenCareOfField);

	isDangerousField = new JTextField(10);
	slPanel.putConstraint(SpringLayout.NORTH, isDangerousField, 275, SpringLayout.NORTH, rightPanel);
	slPanel.putConstraint(SpringLayout.WEST, isDangerousField, 93, SpringLayout.WEST, rightPanel);
	rightPanel.add(isDangerousField);

	EnterKeyActionListener enterK = new EnterKeyActionListener();
	nameField.addActionListener(enterK);
	swimField.addActionListener(enterK);
	dangerPercField.addActionListener(enterK);
	legsField.addActionListener(enterK);
	maintCostField.addActionListener(enterK);
	takenCareOfField.addActionListener(enterK);
	isDangerousField.addActionListener(enterK);
}
 
Example 17
Source File: AccessLogTab.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private JComponent searchPanel(final JTable table, final JButton loadMoreButton) {
  final JTextField username = new JTextFieldBuilder().columns(8).build();
  final JTextField ip = new JTextFieldBuilder().columns(6).build();
  final JTextField systemId = new JTextFieldBuilder().columns(10).build();
  final Runnable searchAction =
      () ->
          accessLogTabActions.search(
              AccessLogSearchRequest.builder()
                  .username(username.getText())
                  .ip(ip.getText())
                  .systemId(systemId.getText())
                  .build(),
              table,
              loadMoreButton);

  final JButton searchButton = new JButtonBuilder("Search").actionListener(searchAction).build();
  username.addActionListener(e -> searchAction.run());
  ip.addActionListener(e -> searchAction.run());
  systemId.addActionListener(e -> searchAction.run());

  final JButton searchTips =
      new JButtonBuilder("(SearchTips)")
          .actionListener(
              () ->
                  SwingComponents.showDialog(
                      "Search Tips",
                      "By default all searches are exact matches.\n"
                          + "\n"
                          + "Using '%' is called wildcard matching and matches anything,\n"
                          + "all fields support it.\n\n"
                          + "  Examples:\n\n"
                          + "  user"
                          + "      Finds all usernames exactly matching 'user'\n\n"
                          + "  user%\n"
                          + "      Finds all usernames starting with 'user'\n\n"
                          + "  %user%\n"
                          + "      Finds all usernames containing 'user'\n\n"
                          + "  %user\n"
                          + "      Finds all usernames ending with 'user'\n\n"
                          + "  user%hat\n"
                          + "      Find all usernames starting with 'user'\n"
                          + "      and ending with 'hat'\n"
                          + "\n"
                          + "Entire access log table is searched, no time limit.\n"
                          + "Exact searches and starts-with searches are the least "
                          + "taxing on the database.\n"))
          .build();

  return new JPanelBuilder()
      .flowLayout()
      .addLabel("Username")
      .add(username)
      .addLabel("IP")
      .add(ip)
      .addLabel("System ID")
      .add(systemId)
      .add(searchButton)
      .addLabel("")
      .add(searchTips)
      .build();
}
 
Example 18
Source File: BaseDialog.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
private void processTextField(final JTextField field) {
    field.addActionListener(listener);
}
 
Example 19
Source File: ParametersDialog.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new parameters dialog.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 */
public ParametersDialog(FreeColClient freeColClient, JFrame frame) {
    super(freeColClient, frame);
    /*
     * FIXME: Extend this dialog. It should be possible
     *        to specify the sizes using percentages.
     *
     *        Add a panel containing information about
     *        the scaling (old size, new size etc).
     */        

    JPanel panel = new MigPanel(new MigLayout("wrap 1, center"));
    JPanel widthPanel = new JPanel(new FlowLayout());
    JPanel heightPanel = new JPanel(new FlowLayout());
    String str;
    
    str = Integer.toString(DEFAULT_distToLandFromHighSeas);
    inputD = new JTextField(str, COLUMNS);
    str = Integer.toString(DEFAULT_maxDistanceToEdge);
    inputM = new JTextField(str, COLUMNS);

    str = Messages.message("parametersDialog.determineHighSeas.distToLandFromHighSeas");
    JLabel widthLabel = new JLabel(str);
    widthLabel.setLabelFor(inputD);
    str = Messages.message("parametersDialog.determineHighSeas.maxDistanceToEdge");
    JLabel heightLabel = new JLabel(str);
    heightLabel.setLabelFor(inputM);

    widthPanel.setOpaque(false);
    widthPanel.add(widthLabel);
    widthPanel.add(inputD);
    heightPanel.setOpaque(false);
    heightPanel.add(heightLabel);
    heightPanel.add(inputM);

    panel.add(widthPanel);
    panel.add(heightPanel);
    panel.setSize(panel.getPreferredSize());
    
    final ActionListener al = (ActionEvent ae) -> {
        ParametersDialog.this.checkFields();
    };
    inputD.addActionListener(al);
    inputM.addActionListener(al);

    List<ChoiceItem<Parameters>> c = choices();
    c.add(new ChoiceItem<>(Messages.message("ok"),
                           (Parameters)null).okOption());
    c.add(new ChoiceItem<>(Messages.message("cancel"),
                           (Parameters)null).cancelOption().defaultOption());
    initializeDialog(frame, DialogType.QUESTION, true, panel, null, c);
}
 
Example 20
Source File: ScaleMapSizeDialog.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a ScaleMapSizeDialog.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 */
public ScaleMapSizeDialog(final FreeColClient freeColClient, JFrame frame) {
    super(freeColClient, frame);

    /*
     * FIXME: Extend this dialog. It should be possible to specify
     * the sizes using percentages.
     *
     * Add a panel containing information about the scaling (old
     * size, new size etc).
     */

    JPanel panel = new MigPanel(new MigLayout("wrap 1, center"));
    JPanel widthPanel = new JPanel(new FlowLayout());
    JPanel heightPanel = new JPanel(new FlowLayout());
    String str;

    oldMap = freeColClient.getGame().getMap();
    str = Integer.toString(oldMap.getWidth());
    inputWidth = new JTextField(str, COLUMNS);
    str = Integer.toString(oldMap.getHeight());
    inputHeight = new JTextField(str, COLUMNS);

    JLabel widthLabel = Utility.localizedLabel("width");
    widthLabel.setLabelFor(inputWidth);
    JLabel heightLabel = Utility.localizedLabel("height");
    heightLabel.setLabelFor(inputHeight);

    widthPanel.setOpaque(false);
    widthPanel.add(widthLabel);
    widthPanel.add(inputWidth);
    heightPanel.setOpaque(false);
    heightPanel.add(heightLabel);
    heightPanel.add(inputHeight);

    panel.add(widthPanel);
    panel.add(heightPanel);
    panel.setSize(panel.getPreferredSize());

    final ActionListener al = (ActionEvent ae) -> {
        ScaleMapSizeDialog.this.checkFields();
    };

    inputWidth.addActionListener(al);
    inputHeight.addActionListener(al);

    List<ChoiceItem<Dimension>> c = choices();
    c.add(new ChoiceItem<>(Messages.message("ok"),
                           (Dimension)null).okOption());
    c.add(new ChoiceItem<>(Messages.message("cancel"),
                           (Dimension)null).cancelOption().defaultOption());
    initializeDialog(frame, DialogType.QUESTION, true, panel, null, c);
}