当前位置: 首页>>代码示例>>Java>>正文


Java JTextField.setText方法代码示例

本文整理汇总了Java中javax.swing.JTextField.setText方法的典型用法代码示例。如果您正苦于以下问题:Java JTextField.setText方法的具体用法?Java JTextField.setText怎么用?Java JTextField.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTextField的用法示例。


在下文中一共展示了JTextField.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: chooseFile

import javax.swing.JTextField; //导入方法依赖的package包/类
private void chooseFile(JTextField txtField) {
    JFileChooser chooser = new JFileChooser();
    
    chooser.setCurrentDirectory(null);
    chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
    
    String path = txtField.getText().trim();
    if (path != null && path.length() > 0) {
        chooser.setSelectedFile(new File(path));
    } else if (recentDirectory != null) {
        chooser.setCurrentDirectory(new File(recentDirectory));
    }
    
    
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    
    File selectedFile = chooser.getSelectedFile();
    recentDirectory = selectedFile.getParentFile().getAbsolutePath();
    txtField.setText(selectedFile.getAbsolutePath());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:AdminPropertiesPanel.java

示例2: JFilePicker

import javax.swing.JTextField; //导入方法依赖的package包/类
public JFilePicker(String textFieldLabel, String buttonLabel) {
	
    setLayout(new FlowLayout(FlowLayout.CENTER, 5, 1));
 
    // creates the GUI
    label = new JLabel(textFieldLabel);
    label.setFont(new Font("Arial", Font.BOLD, 16));
     
    textField = new JTextField(30);
    textField.setFont(new Font("Arial", Font.PLAIN, 12));
    textField.setText(WorkspaceFile.getPathWorkspace());
    button = new JButton(buttonLabel);
    button.setFont(new Font("Arial", Font.BOLD, 14));
    
    label.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    textField.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    button.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    
    add(button);
    add(textField);
    add(label);
    
    button.addActionListener(this);     
}
 
开发者ID:BlidiWajdi,项目名称:Mujeed-Arabic-Prolog,代码行数:25,代码来源:JFilePicker.java

示例3: testString

import javax.swing.JTextField; //导入方法依赖的package包/类
public void testString() throws Exception {

        // Test values
        String PROP_NAME = "testText";
        String ORIGINAL_VALUE = "originalValue";
        String NEW_VALUE = "newValue";
        
        // Needed objects
        EditableProperties ep = new EditableProperties(false);
        PropertyEvaluator evaluator = new PlainPropertyEvaluator( ep );
        StoreGroup sg = new StoreGroup();

        // Test correct value of the model
        ep.setProperty( PROP_NAME, ORIGINAL_VALUE );
        Document doc = sg.createStringDocument( evaluator, PROP_NAME );
        JTextField jtf = new JTextField();
        jtf.setDocument( doc );        
        assertEquals( "JTextField has to have correct value", ORIGINAL_VALUE, jtf.getText() );
        
        // Test value is stored
        jtf.setText( NEW_VALUE );        
        sg.store( ep );        
        assertEquals( "Value has to be set into the properties", NEW_VALUE, ep.getProperty( PROP_NAME ) );
        
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:StoreGroupTest.java

示例4: startRename

import javax.swing.JTextField; //导入方法依赖的package包/类
private void startRename() {
	
	// init the text box
	final JTextField text = new JTextField();
	text.setText(m_reference.getNamableName());
	text.setPreferredSize(new Dimension(360, text.getPreferredSize().height));
	text.addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent event) {
			switch (event.getKeyCode()) {
				case KeyEvent.VK_ENTER:
					finishRename(text, true);
				break;
				
				case KeyEvent.VK_ESCAPE:
					finishRename(text, false);
				break;
			}
		}
	});
	
	// find the label with the name and replace it with the text box
	JPanel panel = (JPanel)m_infoPanel.getComponent(0);
	panel.remove(panel.getComponentCount() - 1);
	panel.add(text);
	text.grabFocus();
	text.selectAll();
	
	redraw();
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:31,代码来源:Gui.java

示例5: showDialog

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Creates a dialog and makes it visible, so that the user can choose a file
 * name. The return value indicates if a valid new rule name was input.
 * @param frame the frame on which the dialog is shown.
 * @param title the title for the dialog; if <code>null</code>, a default
 *        title is used
 * @return <code>true</code> if the user agreed with the outcome of the
 *         dialog.
 */
public boolean showDialog(JFrame frame, String title) {
    // set the suggested name in the name field
    JTextField nameField = getNameField();
    nameField.setText(this.suggestion.toString());
    nameField.setSelectionStart(0);
    nameField.setSelectionEnd(nameField.getText()
        .length());
    setOkEnabled();
    JDialog dialog = getOptionPane().createDialog(frame, title == null ? DEFAULT_TITLE : title);
    dialog.setVisible(true);
    Object response = getOptionPane().getValue();
    boolean result = response == getOkButton() || response == getNameField();
    return result;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:24,代码来源:FreshNameDialog.java

示例6: escolherArquivo

import javax.swing.JTextField; //导入方法依赖的package包/类
public void escolherArquivo(JTextField caixaTexto, String extensao) {
    pesquisarArquivo.setFileFilter(new FileNameExtensionFilter(extensao,extensao));
    if (pesquisarArquivo.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        caixaTexto.setText(pesquisarArquivo.getSelectedFile().getAbsolutePath());
    } else {
        JOptionPane.showMessageDialog(this, "Selecione um arquivo!");
    }
}
 
开发者ID:carlinhosxxp,项目名称:RhydoJudge,代码行数:9,代码来源:GerenciarQuestoes.java

示例7: TransferDialog

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Set up and show the dialog. The first Component argument determines which
 * frame the dialog depends on; it should be a component in the dialog's
 * controlling frame. The second Component argument should be null if you
 * want the dialog to come up with its left corner in the center of the
 * screen; otherwise, it should be the component on top of which the dialog
 * should appear.
 */

public TransferDialog(Component frameComp, Component locationComp,
		String title,  I_TickerManager tickerManager) {
	super(frameComp, locationComp, title, tickerManager);

	String[] currencies = {"EUR", "USD", "SEK" , "NOK"};
	currencyList = new JComboBox(currencies);
	currencyList.setEditable(true);
	currencyList.addActionListener(this);
	currencyList.setSelectedIndex(0);
	currencyList.setActionCommand(CURRENCY_CHANGED);
	
	totalCostField = new JTextField(FIELD_LEN);
	totalCostField.setEditable(true);
	totalCostField.setText("");		
	totalCostField.addKeyListener(this);
	
	dateFieldLabel = new JLabel("Maksupäivä: ");
	dateFieldLabel.setLabelFor(dateChooser);


	totalCostFieldLabel = new JLabel("yhteensä: ");
	totalCostFieldLabel.setLabelFor(totalCostField);

	currencyFieldLabel = new JLabel("Valuutta: ");
	
	updateRateFieldCcy((String) currencyList.getSelectedItem(), true);
	init(getDialogLabels(), getDialogComponents());
}
 
开发者ID:skarna1,项目名称:javaportfolio,代码行数:38,代码来源:TransferDialog.java

示例8: addProbability

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Add a probability to an interval Panel If the probability is for
 * interval B the value is displayed as 1-probability
 * 
 * @param intervalPanel
 *            the intervalPanel
 * @param intervalA
 *            if the probability is for interval A or B
 */
protected void addProbability(Container intervalPanel, boolean intervalA) {
	JLabel probLabel = new JLabel(PROBABILITY);
	JTextField probValue = new JTextField();
	Double probability = (Double) current.getParameter(0).getValue();

	// If the interval is interval A display value directly
	// Otherwise display 1-probability
	if (intervalA) {
		probValue.setName(PROBABILITY_INTERVAL_A);
	} else {
		probability = new Double(1 - probability.doubleValue());
		probValue.setName(PROBABILITY_INTERVAL_B);
	}
	probValue.setText(probability.toString());
	probLabel.setLabelFor(probValue);

	probValue.addFocusListener(new ProbabilityAdapter());
	probValue.addKeyListener(new ProbabilityAdapter());

	GridBagConstraints c = new GridBagConstraints();
	c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last
	c.fill = GridBagConstraints.NONE; // reset to default
	c.weightx = 0.0; // reset to default
	c.weighty = 1.0;
	intervalPanel.add(probLabel, c);

	c.gridwidth = GridBagConstraints.REMAINDER; // end row
	c.fill = GridBagConstraints.HORIZONTAL;
	c.weightx = 1.0;
	c.weighty = 1.0;
	intervalPanel.add(probValue, c);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:42,代码来源:DistributionsEditor.java

示例9: testAccountLoginValidation

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Tests to ensure when a user attempts to log in that it correctly
 * matches the hashed password stored in their account file.
 * Will need to be updated once verifying something other than the label
 * is possible (ie account functionality implemented).
 */
@Test
public void testAccountLoginValidation(){
	JTextField usernameField = dlg.getUsernameField();
	JPasswordField passPrimary = dlg.getPasswordFieldPrimary();
	JPasswordField passVerify = dlg.getPasswordFieldVerify();
	JButton button = dlg.getBtnSignIn();
	
	try {
		AccountManager.createUserAccount("BobTest", "guest");
	} catch (IOException e) {
		assertTrue(false);
		e.printStackTrace();
	}
	
	//Test login to existing account via button
	usernameField.setText("BobTest");
	passPrimary.setText("guest");
	button.doClick();
	if(dlg.getErrorLabel().getText().equals("Successfully logged in.")){
		assertTrue(true);
	}
	else{
		assertTrue(false);
	}		
	AccountManager.removeUserAccount("BobTest");		
}
 
开发者ID:ser316asu,项目名称:Dahlem_SER316,代码行数:33,代码来源:LoginDialogTest.java

示例10: initPanel2

import javax.swing.JTextField; //导入方法依赖的package包/类
private void initPanel2(){
    panel2 = new JPanel();
    panel2.setLayout(new GridLayout(2,1));
    
    testo = new JTextField();
    testo.setVisible(true);
    testo.setEditable(false);
    int soldi = parcheggio.getCassa().getAmmount();
    if (soldi==0) {
        testo.setText("Non ci sono soldi nella cassa.");
    }
    else {
        testo.setText("Ci sono "+soldi+"Euro nella cassa");
    }
    
    JButton bottone = new JButton("Ritira denaro");
    bottone.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent e) {
            int tmp = parcheggio.getCassa().ritira();
            if (tmp==0) {
                testo.setText("Non ci sono soldi nella cassa");
            }
            else {
                testo.setText("Sono stati ritirati "+tmp+"Euro");
            }
        }
    });
    panel2.add(bottone);
    panel2.add(testo);
    this.add(panel2,BorderLayout.NORTH);
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-E,代码行数:33,代码来源:GUIOperatore.java

示例11: addInputString

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Adds an input field to insert a String
 * @param text text to be shown on a label
 * @param property property to be changed in Defaults
 * @param cont container where input field must be added
 */
protected void addInputString(String text, String property, Container cont) {
	JLabel label = new JLabel(text + ":");
	JTextField field = new JTextField(10);
	field.setName(property);
	label.setLabelFor(field);
	field.setText(Defaults.get(property));
	// Sets maximum size to minimal one, otherwise springLayout will stretch this
	field.setMaximumSize(new Dimension(field.getMaximumSize().width, field.getMinimumSize().height));
	field.addKeyListener(stringListener);
	field.addFocusListener(stringListener);
	registeredStringListener.add(field);
	cont.add(label);
	cont.add(field);
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:21,代码来源:DefaultsEditor.java

示例12: generateControl

import javax.swing.JTextField; //导入方法依赖的package包/类
@Override
public JComponent generateControl()
{
	field = new JTextField();
	field.setMaximumSize(new Dimension(Short.MAX_VALUE, 20));

	if( items.size() >= 1 )
	{
		field.setText(((Item) items.get(0)).getValue());
	}

	JButton browse = new JButton("Browse");
	browse.setIcon(new ImageIcon(getClass().getResource("/images/browse.gif")));
	browse.setHorizontalTextPosition(SwingConstants.RIGHT);
	Dimension browseSize = browse.getPreferredSize();
	browseSize.height = 20;
	browse.setMaximumSize(browseSize);
	browse.addActionListener(this);

	JPanel group = new JPanel();
	group.setLayout(new BoxLayout(group, BoxLayout.X_AXIS));
	group.add(field);
	group.add(Box.createRigidArea(new Dimension(5, 0)));
	group.add(browse);
	group.setAlignmentX(Component.LEFT_ALIGNMENT);

	return group;
}
 
开发者ID:equella,项目名称:Equella,代码行数:29,代码来源:GResourceSelector.java

示例13: NuevoPrestamo

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * @wbp.parser.constructor
 */
public NuevoPrestamo(Connection conn,JFrameJTable principal,String nombreuser,int codusuario,int codigoproducto,char tipochooser,String fecha) {
	setIconImage(Toolkit.getDefaultToolkit().getImage(NuevoPrestamo.class.getResource("/biblioteca/images/book.png")));
	setTitle("Modificar pr�stamo");
	this.principal=principal;
	this.conn=conn;
	initComponents();
	
	btnBuscarUsuario.setEnabled(false);
	btnBuscarCodigo.setEnabled(false);
	txtUsuario.setText(nombreuser);
	txtCodigo.setText(""+codigoproducto);
	PKuser=""+codusuario;
	PKproducto=""+codigoproducto;

	switch (tipochooser) {
	case 'L':
		tipo.select("Libro");
		break;
	case 'R':
		tipo.select("Revista");
		break;
	case 'C':
		tipo.select("CDROM");
		break;
	case 'A':
		tipo.select("Articulo");
		break;
	default:
		break;
	}


	fecha_devol = new JDateChooser();
	fecha_devol.setEnabled(false);
	fecha_devol.setBounds(265, 208, 126, 23);
	contentPane.add(fecha_devol);
	fecha_devol.setEnabled(true);
	
	JLabel lblfecha_prestDevol = new JLabel("Fecha de devoluci\u00F3n");
	lblfecha_prestDevol.setBounds(265, 193, 148, 14);
	contentPane.add(lblfecha_prestDevol);
	
	txtFecha_prest = new JTextField();
	txtFecha_prest.setEditable(false);
	txtFecha_prest.setBounds(16, 208, 126, 23);
	contentPane.add(txtFecha_prest);
	txtFecha_prest.setColumns(10);
	txtFecha_prest.setText(fecha);
	
	btnActualizar = new JButton("Actualizar");
	btnActualizar.setBounds(157, 264, 98, 23);
	contentPane.add(btnActualizar);
	btnActualizar.addActionListener(this);
	
	
	setVisible(true);
}
 
开发者ID:JuandeLS3,项目名称:Library-app,代码行数:61,代码来源:NuevoPrestamo.java

示例14: SnifferControl

import javax.swing.JTextField; //导入方法依赖的package包/类
public SnifferControl() {
	super();
	setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
	_hostIpTextField = new JTextField(17);
	_hostIpTextField.setText(Resources.getLabel("sniffer.host.tooltip"));
	final FirstInputListener listener = new FirstInputListener(_hostIpTextField);
	_hostIpTextField.addMouseListener(listener);
	_hostIpTextField.addKeyListener(listener);
	_hostIpTextField.setToolTipText(Resources.getLabel("sniffer.host.tooltip"));
	add(_hostIpTextField);

	final JLabel protocolLabel = new JLabel(Resources.getLabel("protocol.label"));
	protocolLabel.setToolTipText(Resources.getLabel("protocol.desc"));
	add(protocolLabel);
	for (final Protocol type : Protocol.values()) {
		if (type == Protocol.OTHER) {
			continue;
		}
		final JCheckBox check = new JCheckBox(type.name(), type == Protocol.TCP);
		_packets.put(type, check);
		add(check);
	}
	final JLabel portLabel = new JLabel(Resources.getLabel("port.label"));
	portLabel.setToolTipText(Resources.getLabel("port.desc"));
	_allPortCheck = new JCheckBox(Resources.getLabel("all.port.label"));
	_allPortCheck.setToolTipText(Resources.getLabel("all.port.desc"));
	_allPortCheck.setSelected(false);
	add(_allPortCheck);

	_portTF = new JFormattedTextField();
	_portTF.setText("80,443");
	_portTF.setColumns(15);
	//			_portTF.setMaximumSize(new Dimension(30, _portTF.getPreferredSize().height));
	add(portLabel);
	add(_portTF);
	_portTF.setEnabled(true);

	_allPortCheck.addChangeListener(e -> _portTF.setEnabled(!_allPortCheck.isSelected()));

	_filterPacketLengthCheck = new JCheckBox(Resources.getLabel("filter.length"));
	_filterPacketLengthCheck.setToolTipText(Resources.getLabel("filter.length.desc"));
	_filterPacketLengthCheck.setSelected(false);
	add(_filterPacketLengthCheck);

	_filterLengthTF = new JFormattedTextField(new NumberFormatterFactory());
	_filterLengthTF.setText("128");
	_filterLengthTF.setColumns(5);
	add(_filterLengthTF);

	_filterPacketLengthCheck.addChangeListener(e -> _filterLengthTF.setEnabled(_filterPacketLengthCheck.isEnabled() && _filterPacketLengthCheck.isSelected()));
	_capturePeriod = new JFormattedTextField(new NumberFormatterFactory());
	_capturePeriod.setText("0");
	_capturePeriod.setColumns(5);
	add(new JLabel(Resources.getLabel("capture.period")));
	add(_capturePeriod);

	_captureButton = new JButton(GO_IMG);
	_captureButton.setToolTipText(Resources.getLabel("capture.packet.start"));
	add(_captureButton);
	_captureButton.addActionListener(arg0 -> start());
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:62,代码来源:ControlPanel.java

示例15: Ed

import javax.swing.JTextField; //导入方法依赖的package包/类
public Ed(FreeRotator p) {
  nameConfig = new StringConfigurer(null, "Description:  ", p.name);
  cwKeyConfig = new NamedHotKeyConfigurer(null, "Command to rotate clockwise:  ", p.rotateCWKey);
  ccwKeyConfig = new NamedHotKeyConfigurer(null, "Command to rotate counterclockwise:  ", p.rotateCCWKey);
  // random rotate
  rndKeyConfig = new NamedHotKeyConfigurer(null, "Command to rotate randomly:  ", p.rotateRNDKey);
  // end random rotate
  anyConfig = new BooleanConfigurer(null, "Allow arbitrary rotations",
    Boolean.valueOf(p.validAngles.length == 1));
  anyKeyConfig = new NamedHotKeyConfigurer(null, "Command to rotate:  ", p.setAngleKey);
  facingsConfig = new IntConfigurer(null, "Number of allowed facings:  ", p.validAngles.length == 1 ? 6 : p.validAngles.length);

  panel = new JPanel();
  panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

  panel.add(nameConfig.getControls());
  panel.add(facingsConfig.getControls());
  cwControls = Box.createHorizontalBox();
  cwControls.add(cwKeyConfig.getControls());
  cwControls.add(new JLabel(" Menu text:  "));
  cwCommand = new JTextField(12);
  cwCommand.setMaximumSize(cwCommand.getPreferredSize());
  cwCommand.setText(p.rotateCWText);
  cwControls.add(cwCommand);
  panel.add(cwControls);

  ccwControls = Box.createHorizontalBox();
  ccwControls.add(ccwKeyConfig.getControls());
  ccwControls.add(new JLabel(" Menu text:  "));
  ccwCommand = new JTextField(12);
  ccwCommand.setMaximumSize(ccwCommand.getPreferredSize());
  ccwCommand.setText(p.rotateCCWText);
  ccwControls.add(ccwCommand);
  panel.add(ccwControls);

  panel.add(anyConfig.getControls());
  anyControls = Box.createHorizontalBox();
  anyControls.add(anyKeyConfig.getControls());
  anyControls.add(new JLabel(" Menu text:  "));
  anyCommand = new JTextField(12);
  anyCommand.setMaximumSize(anyCommand.getPreferredSize());
  anyCommand.setText(p.setAngleText);
  anyControls.add(anyCommand);
  panel.add(anyControls);

  // random rotate
  rndControls = Box.createHorizontalBox();
  rndControls.add(rndKeyConfig.getControls());
  rndControls.add(new JLabel(" Menu text:  "));
  rndCommand = new JTextField(12);
  rndCommand.setMaximumSize(rndCommand.getPreferredSize());
  rndCommand.setText(p.rotateRNDText);
  rndControls.add(rndCommand);
  panel.add(rndControls);
  // end random rotate

  anyConfig.addPropertyChangeListener(this);
  propertyChange(null);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:60,代码来源:FreeRotator.java


注:本文中的javax.swing.JTextField.setText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。