jtextfield

How to determine the size of a JTextField?

房东的猫 提交于 2019-12-25 02:26:53
问题 I'm doing a program involving the Pythagorean theorem, and wanted to leave a triangle in the middle, with three JTextField around three sides of it. I did it, but the problem is that when I create the JTextField and add it to the desired container, it is immense. It is a very large white rectangle that when I click to enter, get a small letter. So, my question is: How can I change the size of this JTextField to decrease it and avoid unnecessary sizes? P.S:.'m Using Swing and AWT library for

How to make part of a JTextField uneditable

我是研究僧i 提交于 2019-12-25 02:26:26
问题 I wanted to develop a console-like interface, similar to IDLE. That involved determining how to prevent a certain part of the text in a JTextField from being edited. For example: >>> help Where the ">>> " is uneditable. The caret must never move behind a certain position, and the text behind that position cannot be edited in any way. 回答1: I looked at NavigationFilter, but it doesn't seem to prevent keyboard driven manipulation of the caret. This shows how to do it with a NavigationFilter :

How Do I Put JLabel and JTextField on top of Image?

六月ゝ 毕业季﹏ 提交于 2019-12-25 02:24:11
问题 I am trying to create a game where I have a background image and text on top of that in the form of JLabel s. How would I go about doing that? The main reason I'm doing this is so that I can have 2 different text areas with different font sizes. Using g.drawString() will only let you use 1 text size for the whole thing. Here is my code so far: package com.cgp.buildtown; import java.awt.Font; import java.awt.FontFormatException; import java.awt.Graphics; import java.awt.Graphics2D; import java

Flashing color of a JTextField

…衆ロ難τιáo~ 提交于 2019-12-25 00:34:49
问题 I have a JTextField that is cleared if it has invalid content. I would like the background to flash red one or two times to indicate to the user that this has happened. I have tried: field.setBackground(Color.RED); field.setBackground(Color.WHITE); But it is red for such a brief time that it cannot possibly be seen. Any tips? 回答1: The correct solution, almost arrive at by just eric, is to use a Swing Timer, since all the code in the Timer's ActionListener will be called on the Swing event

Get input text without scanner

孤街浪徒 提交于 2019-12-24 21:45:58
问题 I work on a school project and I am now wondering if it is possible to get text from JTextField with get? // Textrutor JTextField textTitel = new JTextField(null, 20); textTitel.setToolTipText("ex. Flickan som lekte med elden"); JTextField textSort = new JTextField(null, 10); textSort.setToolTipText("ex. Skräck, Action"); JTextField textDesc = new JTextField(null, 15); textDesc.setToolTipText("ex. Stieg Larsson"); // Knappar JButton addButton = new JButton("Lägg till"); // Combobox JComboBox

Adding constraint on JTextField

孤人 提交于 2019-12-24 17:18:35
问题 I am making a GUI, in which I am using a number of JTextfield instances to enter the input from the user. I want to specify that this particular (for example : user name) text field is mandatory to fill. How can I do this? JLabel label_2 = new JLabel("User Name"); label_2.setBounds(23, 167, 126, 21); panel_1.add(label_2); textField_2 = new JTextField(); textField_2.setColumns(10); textField_2.setBounds(178, 129, 210, 20); panel_1.add(textField_2); 回答1: you can also use JFormattedTextField

Press TAB to next Java in Vertical axis component

无人久伴 提交于 2019-12-24 16:51:28
问题 I have a panel null layout and have the following code int k=130; int h=10; for (int i=0; i<22; ++i) { jTextFieldArray[i] = new JTextField(); jTextFieldArray[i].setBounds(k, h, 120, 25); String s = Integer.toString(i+1); jTextFieldArray[i].setText(s); h+=30; panel.add(jTextFieldArray[i]); if (i==10) k=430; if (i==10) h=10; } When I press TAB, the cursor will move to the next horizontal Textfield. How can I make it moving or pointing to the next horizontal Textfield 回答1: If my interpretation

How can i prevent CTRL+C on a JTextField in java?

可紊 提交于 2019-12-24 10:47:27
问题 How can i prevent a user from copying the contents of a JTextField? i have the following but i cannot figure a way to get multiple keys at the same time? myTextField.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (!Character.isDigit(c)) { e.consume(); } } }); 回答1: For this, you will have to modify your KeyAdapter so that it can register when a key was pressed and when it was released, so that we may know when both keys were pressed

Keeping the text in a java textField always selected

心不动则不痛 提交于 2019-12-24 08:42:19
问题 While processing output from a java textField, I require to keep the input text always selected. The code I wrote works perfectly except keeping the text in it always selected. Kindly help me to amend the code so that text in the textField always remains selected. I have used ' textField.selectAll();', but it does not work here. private class ButtonClickListener implements ActionListener{ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if( command.equals(

Set the size of JTextField fixed in a JPanel

懵懂的女人 提交于 2019-12-24 06:42:37
问题 for school I am working on a Java GUI program to store some administrative data. Now I want to display eventdata from my DB (mysql) into a JPanel with use of a JTextField, my problem is I can't get the size of the JTextField fixed as it always takes up a lot of place (see picture) Picture: http://postimg.org/image/5pcklo5n1/ Here's my code, anyone some tips? (I am new to java): public void editEvent() { JFrame frEventEdit = new JFrame ("Event Edit Menu"); frEventEdit.setDefaultCloseOperation