List of usage examples for javax.swing JTextField getText
public String getText()
TextComponent
. From source file:krasa.formatter.plugin.ProjectSettingsForm.java
private void browseForFile(@NotNull final JTextField target) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(); descriptor.setHideIgnored(false);//from w ww. j ava 2 s .com descriptor.setTitle("Select config file"); String text = target.getText(); final VirtualFile toSelect = text == null || text.isEmpty() ? getProject().getBaseDir() : LocalFileSystem.getInstance().findFileByPath(text); // 10.5 does not have #chooseFile VirtualFile[] virtualFile = FileChooser.chooseFiles(descriptor, getProject(), toSelect); if (virtualFile != null && virtualFile.length > 0) { target.setText(virtualFile[0].getPath()); } }
From source file:com.all.login.view.NewAccountFormPanel.java
private void capitalizeText(JTextField field) { field.setText(WordUtils.capitalizeFully(field.getText())); }
From source file:gov.nih.nci.nbia.StandaloneDMDispatcher.java
private void install(String downloadUrl) { Double vNum = 0.0;//from w w w . j av a2 s .c o m if (appVersion != null) { vNum = Double.parseDouble(appVersion); } String installerPath = getInstallerName(downloadUrl); if (os.contains("windows")) { try { Runtime.getRuntime().exec("msiexec /i \"" + installerPath + "\""); } catch (Exception e) { e.printStackTrace(); } } else if (os.startsWith("mac")) { try { Runtime.getRuntime().exec(new String[] { "/usr/bin/open", installerPath }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { JLabel pwLabel = new JLabel("Sudo Password"); JTextField password = new JPasswordField(); Object[] objs = { pwLabel, password }; int result = JOptionPane.showConfirmDialog(null, objs, "Please enter a sudo password", JOptionPane.OK_CANCEL_OPTION); String pas = null; if (result == JOptionPane.OK_OPTION) { pas = password.getText(); } if (pas != null) { if (os.equals("CentOS")) { // sudo yum install TCIADownloader-1.0-1.x86_64.rpm try { String upgradCmd = "/usr/bin/sudo -S yum -q -y remove TCIADownloader.x86_64;/usr/bin/sudo -S yum -y -q install "; if (vNum >= 3.2) upgradCmd = "/usr/bin/sudo -S yum -q -y remove NBIADataRetriever.x86_64;/usr/bin/sudo -S yum -y -q install "; String[] cmd = { "/bin/bash", "-c", upgradCmd + installerPath }; Process pb = Runtime.getRuntime().exec(cmd); BufferedWriter writer = null; writer = new BufferedWriter(new OutputStreamWriter(pb.getOutputStream())); writer.write(pas); writer.write('\n'); writer.flush(); String status = null; if (pb.waitFor() == 0) { status = "successfully"; } else { status = "unsuccessfully"; } JOptionPane.showMessageDialog(null, "Installation of new version of NBIA Data Retriever is completed " + status + "."); } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (os.equals("Ubuntu")) { // sudo dpkg -i tciadownloader_1.0-2_amd64.deb String upgradCmd = "/usr/bin/sudo -S dpkg -i "; if (vNum >= 3.2) upgradCmd = "/usr/bin/sudo -S dpkg -i nbia-data-retriever; /usr/bin/sudo -S dpkg -i "; try { String[] cmd = { "/bin/bash", "-c", upgradCmd + installerPath }; Process pb = Runtime.getRuntime().exec(cmd); BufferedWriter writer = null; writer = new BufferedWriter(new OutputStreamWriter(pb.getOutputStream())); writer.write(pas); writer.write('\n'); writer.flush(); String status = null; if (pb.waitFor() == 0) { status = "successfully"; } else { status = "unsuccessfully"; } JOptionPane.showMessageDialog(null, "Installation of new version of NBIA Data Retriever is completed " + status + "."); } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopSuggestionField.java
public DesktopSuggestionField() { composition = new JPanel(); composition.setLayout(new BorderLayout()); composition.setFocusable(false);/*from w w w .j av a 2s .c o m*/ comboBox = new SearchComboBox() { @Override public void setPopupVisible(boolean v) { if (!items.isEmpty()) { super.setPopupVisible(v); } else if (!v) { super.setPopupVisible(false); } } @Override public void actionPerformed(ActionEvent e) { if (SearchAutoCompleteSupport.SEARCH_ENTER_COMMAND.equals(e.getActionCommand())) { enterHandling = true; } super.actionPerformed(e); } }; comboBox.addActionListener(e -> { if (settingValue || disableActionListener) { return; } if ("comboBoxEdited".equals(e.getActionCommand())) { Object selectedItem = comboBox.getSelectedItem(); if (popupItemSelectionHandling) { if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); } } else if (enterHandling) { if (selectedItem instanceof String) { boolean found = false; String newFilter = (String) selectedItem; if (prevValue != null) { if (Objects.equals(getDisplayString(prevValue), newFilter)) { found = true; } } final boolean searchStringEqualsToCurrentValue = found; // we need to do it later // unable to change current text from ActionListener SwingUtilities.invokeLater(() -> { updateComponent(prevValue); if (!searchStringEqualsToCurrentValue) { handleOnEnterAction(((String) selectedItem)); } }); } else if (currentSearchComponentText != null) { // Disable variants after select final String enterActionString = currentSearchComponentText; SwingUtilities.invokeLater(() -> { updateComponent(prevValue); handleOnEnterAction(enterActionString); }); currentSearchComponentText = null; } } clearSearchVariants(); popupItemSelectionHandling = false; enterHandling = false; } SwingUtilities.invokeLater(this::updateEditState); }); Component editorComponent = comboBox.getEditor().getEditorComponent(); editorComponent.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { SwingUtilities.invokeLater(() -> { updateEditState(); if (e.getKeyChar() != '\n') { handleSearchInput(); } }); } @Override public void keyPressed(KeyEvent e) { SwingUtilities.invokeLater(() -> { if (e.getKeyCode() == KeyEvent.VK_DOWN && arrowDownActionHandler != null && !comboBox.isPopupVisible()) { arrowDownActionHandler.onArrowDownKeyPressed(getComboBoxEditorField().getText()); } }); } }); comboBox.setEditable(true); comboBox.setPrototypeDisplayValue("AAAAAAAAAAAA"); autoComplete = SearchAutoCompleteSupport.install(comboBox, items); autoComplete.setFilterEnabled(false); for (int i = 0; i < comboBox.getComponentCount(); i++) { Component component = comboBox.getComponent(i); component.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { clearSearchVariants(); // Reset invalid value checkSelectedValue(); } }); } final JTextField searchEditorComponent = getComboBoxEditorField(); searchEditorComponent.addActionListener(e -> currentSearchComponentText = searchEditorComponent.getText()); // set value only on PopupMenu closing to avoid firing listeners on keyboard navigation comboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { comboBox.updatePopupWidth(); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { if (!autoComplete.isEditableState()) { popupItemSelectionHandling = comboBox.getSelectedIndex() >= 0; // Only if really item changed if (!enterHandling) { Object selectedItem = comboBox.getSelectedItem(); if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); clearSearchVariants(); } } updateMissingValueState(); } } @Override public void popupMenuCanceled(PopupMenuEvent e) { clearSearchVariants(); } }); textField = new JTextField(); textField.setEditable(false); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); valueFormatter = new DefaultValueFormatter(sessionSource.getLocale()); composition.add(comboBox, BorderLayout.CENTER); impl = comboBox; DesktopComponentsHelper.adjustSize(comboBox); Configuration configuration = AppBeans.get(Configuration.NAME); asyncSearchDelayMs = configuration.getConfig(ClientConfig.class).getSuggestionFieldAsyncSearchDelayMs(); }
From source file:caarray.client.test.gui.GuiMain.java
public GuiMain() throws Exception { JFrame frame = new JFrame("API Test Suite"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BorderLayout(6, 6)); JPanel topPanel = new JPanel(); /* ###### Text fields for modifiable parameters ##### */ final JTextField javaHostText = new JTextField(TestProperties.getJavaServerHostname(), 20); JLabel javaHostLabel = new JLabel("Java Service Host"); JButton save = new JButton("Save"); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { TestProperties.setJavaServerHostname(javaHostText.getText()); }/*from w w w . ja va 2s .co m*/ }); JLabel javaPortLabel = new JLabel("Java Port"); final JTextField javaPortText = new JTextField(Integer.toString(TestProperties.getJavaServerJndiPort()), 5); JButton save2 = new JButton("Save"); save2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { int port = Integer.parseInt(javaPortText.getText()); TestProperties.setJavaServerJndiPort(port); } catch (NumberFormatException e) { System.out.println(javaPortText.getText() + " is not a valid port number."); } } }); JLabel gridHostLabel = new JLabel("Grid Service Host"); final JTextField gridHostText = new JTextField(TestProperties.getGridServerHostname(), 20); JButton save3 = new JButton("Save"); save3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { TestProperties.setGridServerHostname(gridHostText.getText()); } }); JLabel gridPortLabel = new JLabel("Grid Service Port"); final JTextField gridPortText = new JTextField(Integer.toString(TestProperties.getGridServerPort()), 5); JButton save4 = new JButton("Save"); save4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { int port = Integer.parseInt(gridPortText.getText()); TestProperties.setGridServerPort(port); } catch (NumberFormatException e) { System.out.println(gridPortText.getText() + " is not a valid port number."); } } }); JLabel excludeLabel = new JLabel("Exclude test cases (comma-separated list):"); final JTextField excludeText = new JTextField("", 30); JButton save5 = new JButton("Save"); save5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String testString = excludeText.getText(); if (testString != null) { String[] testCases = testString.split(","); if (testCases != null && testCases.length > 0) { List<Float> tests = new ArrayList<Float>(); for (String test : testCases) { try { tests.add(Float.parseFloat(test)); } catch (NumberFormatException e) { System.out.println(test + " is not a valid test case."); } } TestProperties.setExcludedTests(tests); } } } }); JLabel includeLabel = new JLabel("Include only (comma-separated list):"); final JTextField includeText = new JTextField("", 30); JButton save6 = new JButton("Save"); save6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String testString = includeText.getText(); if (testString != null) { String[] testCases = testString.split(","); if (testCases != null && testCases.length > 0) { List<Float> tests = new ArrayList<Float>(); for (String test : testCases) { try { tests.add(Float.parseFloat(test)); } catch (NumberFormatException e) { System.out.println(test + " is not a valid test case."); } } TestProperties.setIncludeOnlyTests(tests); } } } }); JLabel threadLabel = new JLabel("Number of threads:"); final JTextField threadText = new JTextField(Integer.toString(TestProperties.getNumThreads()), 5); JButton save7 = new JButton("Save"); save7.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { int threads = Integer.parseInt(threadText.getText()); TestProperties.setNumThreads(threads); } catch (NumberFormatException e) { System.out.println(threadText.getText() + " is not a valid thread number."); } } }); GridBagLayout topLayout = new GridBagLayout(); topPanel.setLayout(topLayout); JLabel[] labels = new JLabel[] { javaHostLabel, javaPortLabel, gridHostLabel, gridPortLabel, excludeLabel, includeLabel, threadLabel }; JTextField[] textFields = new JTextField[] { javaHostText, javaPortText, gridHostText, gridPortText, excludeText, includeText, threadText }; JButton[] buttons = new JButton[] { save, save2, save3, save4, save5, save6, save7 }; for (int i = 0; i < labels.length; i++) { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = i; topPanel.add(labels[i], c); c.gridx = 1; topPanel.add(textFields[i], c); c.gridx = 2; topPanel.add(buttons[i], c); } frame.getContentPane().add(topPanel, BorderLayout.PAGE_START); GridLayout bottomLayout = new GridLayout(0, 4); selectionPanel.setLayout(bottomLayout); JCheckBox selectAll = new JCheckBox("Select/Deselect All"); selectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBox box = (JCheckBox) e.getSource(); selectAll(box.isSelected()); } }); selectionPanel.add(selectAll); JCheckBox excludeLongTests = new JCheckBox("Exclude Long Tests"); excludeLongTests.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBox box = (JCheckBox) e.getSource(); if (box.isSelected()) { TestProperties.excludeLongTests(); } else { TestProperties.removeExcludedLongTests(); } } }); TestProperties.excludeLongTests(); excludeLongTests.setSelected(true); selectionPanel.add(excludeLongTests); //Initialize check boxes corresponding to test categories initializeTests(); centerPanel.setLayout(new GridLayout(0, 1)); centerPanel.add(selectionPanel); //Redirect System messages to gui JScrollPane textScroll = new JScrollPane(); textScroll.setViewportView(textDisplay); System.setOut(new PrintStream(new JTextAreaOutputStream(textDisplay))); System.setErr(new PrintStream(new JTextAreaOutputStream(textDisplay))); centerPanel.add(textScroll); JScrollPane scroll = new JScrollPane(centerPanel); frame.getContentPane().add(scroll, BorderLayout.CENTER); JButton runButton = new JButton("Run Tests"); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { runTests(); } catch (Exception e) { System.out.println("An error occured executing the tests: " + e.getClass() + ". Check error log for details."); log.error("Exception encountered:", e); } } }); JPanel bottomPanel = new JPanel(); bottomPanel.add(runButton); frame.getContentPane().add(bottomPanel, BorderLayout.PAGE_END); frame.pack(); frame.setVisible(true); }
From source file:lab4.YouQuiz.java
private void updateAnswerForm() { contentPanel.answerPanel.removeAll(); final Question question = questionsArray.get(questionIndex); switch (question.type) { case Question.QUESTION_TYPE_MULTIPLE_CHOICE: case Question.QUESTION_TYPE_TRUE_FALSE: JRadioButton radioButton; final ButtonGroup radioGroup = new ButtonGroup(); for (int i = 0; i < ((MultipleChoiceQuestion) question).getChoices().size(); ++i) { radioButton = new JRadioButton(((MultipleChoiceQuestion) question).getChoices().get(i)); radioButton.setFont(new Font("Consolas", Font.PLAIN, 20)); radioGroup.add(radioButton); radioButton.setFocusable(false); contentPanel.answerPanel.add(radioButton); }/* w ww . j ava2 s . c o m*/ for (ActionListener al : contentPanel.checkButton.getActionListeners()) { contentPanel.checkButton.removeActionListener(al); } contentPanel.checkButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (question.checkAnswer(getSelectedButtonText(radioGroup))) { JOptionPane.showMessageDialog(null, "Thats Great, Correct Answer", "Excellent", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Oops! Wrong Answer. Its '" + question.getAnswer().get(0) + "'", "Sorry", JOptionPane.ERROR_MESSAGE); } } }); break; case Question.QUESTION_TYPE_SHORT_ANSWER: final JTextField answerText = new JTextField(25); answerText.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20)); contentPanel.answerPanel.add(answerText); for (ActionListener al : contentPanel.checkButton.getActionListeners()) { contentPanel.checkButton.removeActionListener(al); } contentPanel.checkButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (question.checkAnswer(answerText.getText())) { JOptionPane.showMessageDialog(null, "Thats Great, Correct Answer", "Excellent", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Oops! Wrong Answer. Its '" + question.getAnswer().get(0) + "'", "Sorry", JOptionPane.ERROR_MESSAGE); } } }); break; } contentPanel.answerPanel.invalidate(); }
From source file:course_generator.param.frmEditCurve.java
/** * Duplicate the selected curve/*from ww w .jav a2 s . c o m*/ * Its new name is requested */ private void DuplicateCurve() { if (!bEditMode) { Old_Paramfile = Paramfile; //-- Configuration of the panel JPanel panel = new JPanel(new GridLayout(0, 1)); panel.add(new JLabel(bundle.getString("frmEditCurve.DuplicatePanel.name.text"))); JTextField tfName = new JTextField(""); panel.add(tfName); int result = JOptionPane.showConfirmDialog(this, panel, bundle.getString("frmEditCurve.DuplicatePanel.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if ((result == JOptionPane.OK_OPTION) && (!tfName.getText().isEmpty())) { if (Utils.FileExist(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/" + tfName.getText() + ".par")) { JOptionPane.showMessageDialog(this, bundle.getString("frmEditCurve.DuplicatePanel.fileexist")); return; } param.name = tfName.getText(); Paramfile = param.name; param.Save(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/" + param.name + ".par"); ChangeEditStatus(); RefreshCurveList(); RefreshView(); } } }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.GUIComponents.FLIMPanel.java
private void updateDelayField(JTextField field) { int num = 0;//from w w w .j av a2 s .co m int min = 0; int max = 16666; int inc = 25; try { max = Integer.parseInt(core_.getProperty("Laser", "Frequency")); } catch (Exception e) { } if (!field.getText().isEmpty()) { num = Integer.parseInt(field.getText()); if (num > max) num = max; else if (num < min) num = min; num = round(num / inc) * inc; } else { num = min; } field.setText(String.valueOf(num)); }
From source file:course_generator.param.frmEditCurve.java
/** * Add a new curve to the curve list// w w w .j a v a2 s . co m */ protected void AddCurve() { if (!bEditMode) { JPanel panel = new JPanel(new GridLayout(0, 1)); panel.add(new JLabel(bundle.getString("frmEditCurve.AddCurvePanel.name.text"))); JTextField tfName = new JTextField(""); panel.add(tfName); int result = JOptionPane.showConfirmDialog(this, panel, bundle.getString("frmEditCurve.AddCurvePanel.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if ((result == JOptionPane.OK_OPTION) && (!tfName.getText().isEmpty())) { if (Utils.FileExist(Utils.GetHomeDir() + "/" + CgConst.CG_DIR + "/" + tfName.getText() + ".par")) { JOptionPane.showMessageDialog(this, bundle.getString("frmEditCurve.AddCurvePanelPanel.fileexist")); return; } //-- Add the 2 extrem points to the list and sort the list (not really necessary...) param = new ParamData(); param.name = tfName.getText(); param.data.add(new CgParam(-50.0, 0)); param.data.add(new CgParam(50.0, 0)); Collections.sort(param.data); //-- Update tablemodel.setParam(param); Old_Paramfile = Paramfile; Paramfile = param.name; bEditMode = true; ChangeEditStatus(); RefreshView(); } } }
From source file:krasa.formatter.plugin.ProjectSettingsForm.java
private ComboBoxModel createProfilesModel(JTextField pathToEclipsePreferenceFile, String selectedProfile) { SortedComboBoxModel<String> profilesModel = new SortedComboBoxModel<String>(new Comparator<String>() { @Override/* ww w . jav a 2 s.c om*/ public int compare(String o1, String o2) { return o1.compareTo(o2); } }); String text = pathToEclipsePreferenceFile.getText(); if (!text.isEmpty()) { if (text.endsWith("xml")) { try { profilesModel.addAll(FileUtils.getProfileNamesFromConfigXML(new File(text))); } catch (ParsingFailedException e) { profilesModel.add(PARSING_FAILED); } } else { // not xml } } else { // empty } List<String> items = profilesModel.getItems(); if (items.size() > 0) { for (String item : items) { if (item.equals(selectedProfile)) { profilesModel.setSelectedItem(item); } } if (profilesModel.getSelectedItem() == null) { profilesModel.setSelectedItem(items.get(0)); } } return profilesModel; }