Java Code Examples for javax.swing.JTextField#setEnabled()
The following examples show how to use
javax.swing.JTextField#setEnabled() .
These examples are extracted from open source projects.
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 Project: triplea File: ServerSetupPanel.java License: GNU General Public License v3.0 | 6 votes |
private void createComponents() { final IServerMessenger messenger = model.getMessenger(); final Color backGround = new JTextField().getBackground(); portField = new JTextField("" + messenger.getLocalNode().getPort()); portField.setEnabled(true); portField.setEditable(false); portField.setBackground(backGround); portField.setColumns(6); addressField = new JTextField(messenger.getLocalNode().getAddress().getHostAddress()); addressField.setEnabled(true); addressField.setEditable(false); addressField.setBackground(backGround); addressField.setColumns(20); nameField = new JTextField(messenger.getLocalNode().getName()); nameField.setEnabled(true); nameField.setEditable(false); nameField.setBackground(backGround); nameField.setColumns(20); info = new JPanel(); networkPanel = new JPanel(); }
Example 2
Source Project: gcs File: BaseSpellEditor.java License: Mozilla Public License 2.0 | 6 votes |
/** * Utility function to create a text field (with a label) and set a few properties. * * @param labelParent Container for the label. * @param fieldParent Container for the text field. * @param title The text of the label. * @param text The text of the text field. * @param tooltip The tooltip of the text field. */ protected JTextField createCorrectableField(Container labelParent, Container fieldParent, String title, String text, String tooltip) { JTextField field = new JTextField(text); field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip)); field.setEnabled(mIsEditable); field.getDocument().addDocumentListener(this); field.addActionListener(this); field.addFocusListener(this); LinkedLabel label = new LinkedLabel(title); label.setLink(field); labelParent.add(label); fieldParent.add(field); return field; }
Example 3
Source Project: triplea File: JTextFieldBuilder.java License: GNU General Public License v3.0 | 6 votes |
/** Builds the swing component. */ public JTextField build() { final JTextField textField = new JTextField(Strings.nullToEmpty(this.text)); Optional.ofNullable(columns).ifPresent(textField::setColumns); Optional.ofNullable(actionListener) .ifPresent(action -> textField.addActionListener(e -> action.accept(textField))); Optional.ofNullable(textListener) .ifPresent( listener -> new DocumentListenerBuilder(() -> textListener.accept(textField.getText())) .attachTo(textField)); Optional.ofNullable(maxLength).map(JTextFieldLimit::new).ifPresent(textField::setDocument); Optional.ofNullable(text).ifPresent(textField::setText); Optional.ofNullable(toolTip).ifPresent(textField::setToolTipText); textField.setEnabled(enabled); textField.setEditable(!readOnly); return textField; }
Example 4
Source Project: gcs File: TechniqueEditor.java License: Mozilla Public License 2.0 | 6 votes |
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); field.addActionListener(this); if (labelParent != null) { labelParent.add(new LinkedLabel(title, field)); } fieldParent.add(field); return field; }
Example 5
Source Project: RobotBuilder File: RelativePathAccessory.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
private void addComponents() { setLayout(new GridLayout(4, 1)); relative = new JRadioButton("Use path relative to the RobotBuilder save file."); relative.setSelected(true); relativePreview = new JTextField("."); relativePreview.setEditable(false); relativePreview.setEnabled(false); relativePreview.setForeground(Color.BLACK); absolute = new JRadioButton("Use absolute path."); absolutePreview = new JTextField(""); absolutePreview.setEditable(false); absolutePreview.setEnabled(false); absolutePreview.setForeground(Color.BLACK); options = new ButtonGroup(); options.add(relative); options.add(absolute); add(relative); add(relativePreview); add(absolute); add(absolutePreview); }
Example 6
Source Project: gcs File: TechniqueEditor.java License: Mozilla Public License 2.0 | 5 votes |
private JTextField createCorrectableField(Container labelParent, Container fieldParent, String title, String text, String tooltip) { JTextField field = new JTextField(text); field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip)); field.setEnabled(mIsEditable); field.getDocument().addDocumentListener(this); if (labelParent != null) { LinkedLabel label = new LinkedLabel(title); label.setLink(field); labelParent.add(label); } fieldParent.add(field); return field; }
Example 7
Source Project: zxpoly File: FileNameDialog.java License: GNU General Public License v3.0 | 5 votes |
private void processZxFileType(final JTextField field, final char[] array, final int index) { if (array == null || array[index] == 0) { field.setEnabled(false); } else { field.setText(Character.toString(array[index])); } }
Example 8
Source Project: lizzie File: NewGameDialog.java License: GNU General Public License v3.0 | 5 votes |
private void togglePlayerIsBlack() { JTextField humanTextField = playerIsBlack() ? textFieldBlack : textFieldWhite; JTextField computerTextField = playerIsBlack() ? textFieldWhite : textFieldBlack; humanTextField.setEnabled(true); humanTextField.setText(GameInfo.DEFAULT_NAME_HUMAN_PLAYER); computerTextField.setEnabled(false); computerTextField.setText(GameInfo.DEFAULT_NAME_CPU_PLAYER); }
Example 9
Source Project: zxpoly File: FileNameDialog.java License: GNU General Public License v3.0 | 5 votes |
private void processFileName(final JTextField field, final String[] array, final int index) { if (array == null || array[index] == null) { field.setEnabled(false); } else { field.setText(array[index]); } }
Example 10
Source Project: openstego File: CommonUtil.java License: GNU General Public License v2.0 | 5 votes |
/** * Method to enable/disable a Swing JTextField object * * @param textField Swing JTextField object * @param enabled Flag to indicate whether to enable or disable the object */ public static void setEnabled(JTextField textField, boolean enabled) { if (enabled) { textField.setEnabled(true); textField.setBackground(Color.WHITE); } else { textField.setEnabled(false); textField.setBackground(UIManager.getColor("Panel.background")); } }
Example 11
Source Project: gcs File: EquipmentModifierEditor.java License: Mozilla Public License 2.0 | 5 votes |
private JTextField createCorrectableField(Container labelParent, Container fieldParent, String title, String text, String tooltip) { JTextField field = new JTextField(text); field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip)); field.setEnabled(mIsEditable); field.getDocument().addDocumentListener(this); LinkedLabel label = new LinkedLabel(title); label.setLink(field); labelParent.add(label); fieldParent.add(field); return field; }
Example 12
Source Project: javamoney-examples File: Form.java License: Apache License 2.0 | 5 votes |
/** * This method enables or disables the elements of the from depending of the * specified value. * * @param value true or false. */ protected void enableForm(boolean value) { // Enable buttons. for(AbstractButton button : getButtons()) { button.setEnabled(value); } // Enable fields. for(JTextField field : getFields()) { field.setEnabled(value); } // Enable choosers. getPayToChooser().setEnabled(value); getPayFromChooser().setEnabled(value); // Set defaults. getButton(NEW).setEnabled(true); // Splits are only for non-transfers. if(value == true && getType() == TRANSFER) { getButton(SPLIT).setEnabled(false); } }
Example 13
Source Project: IrScrutinizer File: IrpMasterBean.java License: GNU General Public License v3.0 | 5 votes |
private void checkParam(JTextField textField, JLabel label, String parameterName, String oldValueStr) { if (protocol.hasParameter(parameterName)) { // TODO: check validity textField.setEnabled(true); label.setEnabled(true); if (!oldValueStr.equals(invalidParameterString)) textField.setText(oldValueStr); } else { textField.setEnabled(false); label.setEnabled(false); textField.setText(null); } }
Example 14
Source Project: niftyeditor File: FileChooserEditor.java License: Apache License 2.0 | 5 votes |
private JPanel createAccessor(){ JPanel result = new JPanel(); BoxLayout layout = new BoxLayout(result, BoxLayout.Y_AXIS); result.setLayout(layout); absolute = new JRadioButton("Absolute path"); relative = new JRadioButton("Relative to Assets folder"); copy = new JRadioButton("Copy file in Assets folder"); copy.addActionListener(this); JTextField absText = new JTextField(); absText.setEditable(false); JTextField relText = new JTextField(); relText.setEditable(false); copyText = new JTextField(); copyText.setMaximumSize(new Dimension(400, 25)); copyText.setEnabled(false); group = new ButtonGroup(); group.add(copy); group.add(relative); group.add(absolute); absolute.setSelected(true); result.add(new ImagePreview(jFileChooser1)); result.add(absolute); result.add(relative); result.add(copy); result.add(copyText); result.add(new JPanel()); return result; }
Example 15
Source Project: gcs File: EquipmentEditor.java License: Mozilla Public License 2.0 | 5 votes |
@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 16
Source Project: snap-desktop File: AddElevationAction.java License: GNU General Public License v3.0 | 4 votes |
private DialogData requestDialogData(final Product product) { boolean ortorectifiable = isOrtorectifiable(product); String[] demNames = DEMFactory.getDEMNameList(); // sort the list final List<String> sortedDEMNames = Arrays.asList(demNames); java.util.Collections.sort(sortedDEMNames); demNames = sortedDEMNames.toArray(new String[sortedDEMNames.size()]); final DialogData dialogData = new DialogData("SRTM 3sec (Auto Download)", ResamplingFactory.BILINEAR_INTERPOLATION_NAME, ortorectifiable); PropertySet propertySet = PropertyContainer.createObjectBacked(dialogData); configureDemNameProperty(propertySet, "demName", demNames, "SRTM 3sec (Auto Download)"); configureDemNameProperty(propertySet, "resamplingMethod", ResamplingFactory.resamplingNames, ResamplingFactory.BILINEAR_INTERPOLATION_NAME); configureBandNameProperty(propertySet, "elevationBandName", product); configureBandNameProperty(propertySet, "latitudeBandName", product); configureBandNameProperty(propertySet, "longitudeBandName", product); final BindingContext ctx = new BindingContext(propertySet); JList demList = new JList(); demList.setVisibleRowCount(10); ctx.bind("demName", new SingleSelectionListComponentAdapter(demList)); JTextField elevationBandNameField = new JTextField(); elevationBandNameField.setColumns(10); ctx.bind("elevationBandName", elevationBandNameField); JCheckBox outputDemCorrectedBandsChecker = new JCheckBox("Output DEM-corrected bands"); ctx.bind("outputDemCorrectedBands", outputDemCorrectedBandsChecker); JLabel latitudeBandNameLabel = new JLabel("Latitude band name:"); JTextField latitudeBandNameField = new JTextField(); latitudeBandNameField.setEnabled(ortorectifiable); ctx.bind("latitudeBandName", latitudeBandNameField).addComponent(latitudeBandNameLabel); ctx.bindEnabledState("latitudeBandName", true, "outputGeoCodingBands", true); JLabel longitudeBandNameLabel = new JLabel("Longitude band name:"); JTextField longitudeBandNameField = new JTextField(); longitudeBandNameField.setEnabled(ortorectifiable); ctx.bind("longitudeBandName", longitudeBandNameField).addComponent(longitudeBandNameLabel); ctx.bindEnabledState("longitudeBandName", true, "outputGeoCodingBands", true); TableLayout tableLayout = new TableLayout(2); tableLayout.setTableAnchor(TableLayout.Anchor.WEST); tableLayout.setTableFill(TableLayout.Fill.HORIZONTAL); tableLayout.setTablePadding(4, 4); tableLayout.setCellColspan(0, 0, 2); tableLayout.setCellColspan(1, 0, 2); /* tableLayout.setCellColspan(3, 0, 2); tableLayout.setCellWeightX(0, 0, 1.0); tableLayout.setRowWeightX(1, 1.0); tableLayout.setCellWeightX(2, 1, 1.0); tableLayout.setCellWeightX(4, 1, 1.0); tableLayout.setCellWeightX(5, 1, 1.0); tableLayout.setCellPadding(4, 0, new Insets(0, 24, 0, 4)); tableLayout.setCellPadding(5, 0, new Insets(0, 24, 0, 4)); */ JPanel parameterPanel = new JPanel(tableLayout); /*row 0*/ parameterPanel.add(new JLabel("Digital elevation model (DEM):")); parameterPanel.add(new JScrollPane(demList)); /*row 1*/ parameterPanel.add(new JLabel("Resampling method:")); final JComboBox resamplingCombo = new JComboBox(DEMFactory.getDEMResamplingMethods()); parameterPanel.add(resamplingCombo); ctx.bind("resamplingMethod", resamplingCombo); parameterPanel.add(new JLabel("Elevation band name:")); parameterPanel.add(elevationBandNameField); if (ortorectifiable) { /*row 2*/ parameterPanel.add(outputDemCorrectedBandsChecker); /*row 3*/ parameterPanel.add(latitudeBandNameLabel); parameterPanel.add(latitudeBandNameField); /*row 4*/ parameterPanel.add(longitudeBandNameLabel); parameterPanel.add(longitudeBandNameField); outputDemCorrectedBandsChecker.setSelected(ortorectifiable); outputDemCorrectedBandsChecker.setEnabled(ortorectifiable); } final ModalDialog dialog = new ModalDialog(SnapApp.getDefault().getMainFrame(), DIALOG_TITLE, ModalDialog.ID_OK_CANCEL, HELP_ID); dialog.setContent(parameterPanel); if (dialog.show() == ModalDialog.ID_OK) { return dialogData; } return null; }
Example 17
Source Project: pentaho-reporting File: JdbcDataSourceDialog.java License: GNU Lesser General Public License v2.1 | 4 votes |
/** * Creates the panel which holds the main content of the dialog */ private void initDialog( final DesignTimeContext designTimeContext ) { this.designTimeContext = designTimeContext; setTitle( Messages.getString( "JdbcDataSourceDialog.Title" ) ); setModal( true ); globalTemplateAction = new GlobalTemplateAction(); queryTemplateAction = new QueryTemplateAction(); dialogModel = new NamedDataSourceDialogModel(); dialogModel.addPropertyChangeListener( new ConfirmValidationHandler() ); connectionComponent = new JdbcConnectionPanel( dialogModel, designTimeContext ); maxPreviewRowsSpinner = new JSpinner( new SpinnerNumberModel( 10000, 1, Integer.MAX_VALUE, 1 ) ); final QueryNameTextFieldDocumentListener updateHandler = new QueryNameTextFieldDocumentListener(); dialogModel.getQueries().addListDataListener( updateHandler ); queryNameList = new JList( dialogModel.getQueries() ); queryNameList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); queryNameList.setVisibleRowCount( 5 ); queryNameList.addListSelectionListener( new QuerySelectedHandler() ); queryNameTextField = new JTextField(); queryNameTextField.setColumns( 35 ); queryNameTextField.setEnabled( dialogModel.isQuerySelected() ); queryNameTextField.getDocument().addDocumentListener( updateHandler ); queryTextArea = new RSyntaxTextArea(); queryTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_SQL ); queryTextArea.setEnabled( dialogModel.isQuerySelected() ); queryTextArea.getDocument().addDocumentListener( new QueryDocumentListener() ); globalScriptTextArea = new RSyntaxTextArea(); globalScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE ); globalLanguageField = new SmartComboBox<ScriptEngineFactory>( new DefaultComboBoxModel( DataFactoryEditorSupport.getScriptEngineLanguages() ) ); globalLanguageField.setRenderer( new QueryLanguageListCellRenderer() ); globalLanguageField.addActionListener( new UpdateScriptLanguageHandler() ); queryScriptTextArea = new RSyntaxTextArea(); queryScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE ); queryScriptTextArea.getDocument().addDocumentListener( new QueryScriptDocumentListener() ); queryLanguageListCellRenderer = new QueryLanguageListCellRenderer(); queryLanguageField = new SmartComboBox<ScriptEngineFactory>( new DefaultComboBoxModel( DataFactoryEditorSupport.getScriptEngineLanguages() ) ); queryLanguageField.setRenderer( queryLanguageListCellRenderer ); queryLanguageField.addActionListener( new UpdateScriptLanguageHandler() ); super.init(); }
Example 18
Source Project: COMP3204 File: EucMatchingDemo.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Component getComponent(int width, int height) throws IOException { engine.getOptions().setDoubleInitialImage(false); final JPanel outer = new JPanel(); outer.setOpaque(false); outer.setPreferredSize(new Dimension(width, height)); outer.setLayout(new GridBagLayout()); // the main panel final JPanel base = new JPanel(); base.setOpaque(false); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); vc = new VideoCaptureComponent(320, 240); vc.getDisplay().getScreen().setPreferredSize(new Dimension(640, 240)); vc.getDisplay().addVideoListener(this); base.add(vc); final JPanel controls1 = new JPanel(); controls1.setOpaque(false); final JButton grab = new JButton("Grab"); grab.setActionCommand("grab"); grab.addActionListener(this); grab.setFont(FONT); controls1.add(grab); base.add(controls1); final JPanel controls = new JPanel(); controls.setOpaque(false); final JLabel label = new JLabel("Threshold:"); label.setFont(FONT); controls.add(label); final JSlider slider = new JSlider(0, 100000); matcher.setThreshold(slider.getValue()); slider.setPreferredSize(new Dimension(slider.getPreferredSize().width + 250, slider.getPreferredSize().height)); controls.add(slider); final JTextField tf = new JTextField(5); tf.setFont(FONT); tf.setEnabled(false); tf.setText(slider.getValue() + ""); controls.add(tf); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { tf.setText(slider.getValue() + ""); matcher.setThreshold(slider.getValue()); } }); base.add(controls); outer.add(base); return outer; }
Example 19
Source Project: megamek File: HostDialog.java License: GNU General Public License v2.0 | 4 votes |
/** Constructs a host game dialog for hosting or loading a game. */ public HostDialog(JFrame frame) { super(frame, Messages.getString("MegaMek.HostDialog.title"), true); //$NON-NLS-1$ JLabel yourNameL = new JLabel( Messages.getString("MegaMek.yourNameL"), SwingConstants.RIGHT); //$NON-NLS-1$ JLabel serverPassL = new JLabel( Messages.getString("MegaMek.serverPassL"), SwingConstants.RIGHT); //$NON-NLS-1$ JLabel portL = new JLabel( Messages.getString("MegaMek.portL"), SwingConstants.RIGHT); //$NON-NLS-1$ yourNameF = new JTextField(cPrefs.getLastPlayerName(), 16); yourNameL.setLabelFor(yourNameF); yourNameF.addActionListener(this); serverPassF = new JTextField(cPrefs.getLastServerPass(), 16); serverPassL.setLabelFor(serverPassF); serverPassF.addActionListener(this); portF = new JTextField(cPrefs.getLastServerPort() + "", 4); //$NON-NLS-1$ portL.setLabelFor(portF); portF.addActionListener(this); metaserver = cPrefs.getMetaServerName(); JLabel metaserverL = new JLabel( Messages.getString("MegaMek.metaserverL"), SwingConstants.RIGHT); //$NON-NLS-1$ metaserverF = new JTextField(metaserver); metaserverL.setEnabled(register); metaserverL.setLabelFor(metaserverF); metaserverF.setEnabled(register); registerC = new JCheckBox(Messages.getString("MegaMek.registerC")); //$NON-NLS-1$ register = false; registerC.setSelected(register); metaserverL.setEnabled(registerC.isSelected()); metaserverF.setEnabled(registerC.isSelected()); registerC.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { metaserverL.setEnabled(registerC.isSelected()); metaserverF.setEnabled(registerC.isSelected()); } }); JPanel middlePanel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; c.insets = new Insets(5, 5, 5, 5); c.gridwidth = 1; c.anchor = GridBagConstraints.EAST; addOptionRow(middlePanel, c, yourNameL, yourNameF); addOptionRow(middlePanel, c, serverPassL, serverPassF); addOptionRow(middlePanel, c, portL, portF); c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.WEST; middlePanel.add(registerC, c); addOptionRow(middlePanel, c, metaserverL, metaserverF); add(middlePanel, BorderLayout.CENTER); // The buttons JButton okayB = new JButton(new OkayAction(this)); JButton cancelB = new ButtonEsc(new CloseAction(this)); JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(okayB); buttonPanel.add(cancelB); add(buttonPanel, BorderLayout.PAGE_END); pack(); setResizable(false); center(); }
Example 20
Source Project: pentaho-reporting File: QueryEditorPanel.java License: GNU Lesser General Public License v2.1 | 4 votes |
@SuppressWarnings( "unchecked" ) private void init() { globalTemplateAction = new GlobalTemplateAction( this, dialogModel ); queryTemplateAction = new QueryTemplateAction( this, dialogModel ); queryNameList = new JList( dialogModel.getQueries() ); queryNameList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); queryNameList.setVisibleRowCount( 5 ); queryNameList.setCellRenderer( new QueryListCellRenderer() ); queryNameList.addListSelectionListener( new QuerySelectedHandler( dialogModel, queryNameList ) ); queryNameTextField = new JTextField(); queryNameTextField.setColumns( 35 ); queryNameTextField.setEnabled( dialogModel.isQuerySelected() ); queryNameTextField.getDocument().addDocumentListener( new QueryNameUpdateHandler() ); globalScriptTextArea = new RSyntaxTextArea(); globalScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE ); globalScriptTextArea.getDocument().addDocumentListener( new GlobalScriptUpdateHandler() ); globalLanguageField = new SmartComboBox( new DefaultComboBoxModel( DataFactoryEditorSupport.getScriptEngineLanguages() ) ); globalLanguageField.setRenderer( new QueryLanguageListCellRenderer() ); globalLanguageField.addActionListener( new UpdateGlobalScriptLanguageHandler() ); queryScriptTextArea = new RSyntaxTextArea(); queryScriptTextArea.setSyntaxEditingStyle( SyntaxConstants.SYNTAX_STYLE_NONE ); queryScriptTextArea.getDocument().addDocumentListener( new QueryScriptUpdateHandler() ); queryLanguageField = new SmartComboBox( new DefaultComboBoxModel( DataFactoryEditorSupport.getScriptEngineLanguages() ) ); queryLanguageListCellRenderer = new QueryLanguageListCellRenderer(); queryLanguageField.setRenderer( queryLanguageListCellRenderer ); queryLanguageField.addActionListener( new UpdateQueryScriptLanguageHandler() ); dialogModel.addQueryDialogModelListener( new DialogModelChangesDispatcher() ); initialize(); createComponents(); }