jtextfield

set a JTextField width in maner to wrap a given text

岁酱吖の 提交于 2019-12-23 12:55:50
问题 I have an uneditable and disabled JtextField in which I will put a String obtained after requesting a Database, and I want that this JtextField wraps All my String. I saw the setColumn() and setSize() methods but I don't know first my String length. thank you very much. 回答1: JTextFields can only display a single line of text, period. If you need a simple text component that wraps text, use a JTextArea. Set its columns and rows. Put it into a JScrollPane (if you feel the text will go beyond

How to make a text field for searching(with tips like a google search)

雨燕双飞 提交于 2019-12-23 10:55:10
问题 I want to make a window application for PC using java swing. I would like to make a text field there. While typing to that text field I need it to show tips under that text field. And user can select the needed text from the list. The same like the google searching does in the browser. So I need some two functions, first one is easy: filter a set of strings by already typed text. But how to show them in a list ? EDIT1: I need the list to be shown if there is something to show after filtration

How to simulate Keyboard press in java

耗尽温柔 提交于 2019-12-23 10:06:08
问题 I want to simulate entering a string (can contain any character) in JTextField. I am using new KeyEventData() for that. But I am not able to determine how to handle characters like {, }, ) etc and also how to append a new character to already entered characters. 回答1: You can use Robot for this, as shown in this example. To get { , for example, you'll need to do something like this: keyPress(KeyEvent.VK_SHIFT); keyPress(KeyEvent.VK_OPEN_BRACKET); keyRelease(KeyEvent.VK_OPEN_BRACKET);

JTextField Fixed Height

送分小仙女□ 提交于 2019-12-23 08:57:45
问题 How do I get the JTextField to have a fixed height when the Frame is maximized? I want it to look sort of similar to the Skype application on Ubuntu. private JTextField username; private JPasswordField password; private JLabel usernamelabel; private JLabel passwordlabel; public LoginPanel(){ setSize(200,200); setLayout(new GridLayout(4,4)); setBackground(new Color(85,153,187)); setBorder(BorderFactory.createEmptyBorder(70, 70, 70, 70)); username = new JTextField(); password = new

JTextField : How to set text on the left of JTextField when text too long

谁说我不能喝 提交于 2019-12-23 08:50:15
问题 I have a long String that I want to display in a JTextField . If the String is too long, it is showing the right-portion of the String , rather than the left portion, even when I use setHorizontalAlignment(JTextField.LEFT) For example, if my String is "JTextField example , this text is too long" , it should show as... |----------------------| | JTextField example ..| |----------------------| but instead it shows as... |----------------------| | this text is too long| |----------------------|

Updating text in a JTextField

僤鯓⒐⒋嵵緔 提交于 2019-12-23 07:05:47
问题 K, so unlike with my last question, I've been proactive about trying to deal with this problem a number of times, and it's still not working. Basically I'm trying implement a JTextField. I've added the action listener to it and the getters and setters for the text are working, but text that I'm enter isn't showing up in the textfield. I tried setting the text color to black and that didn't help. Honestly, I'm not sure what the issue is. K here's the code. import acm.program.*; import java.awt

Updating text in a JTextField

允我心安 提交于 2019-12-23 07:04:38
问题 K, so unlike with my last question, I've been proactive about trying to deal with this problem a number of times, and it's still not working. Basically I'm trying implement a JTextField. I've added the action listener to it and the getters and setters for the text are working, but text that I'm enter isn't showing up in the textfield. I tried setting the text color to black and that didn't help. Honestly, I'm not sure what the issue is. K here's the code. import acm.program.*; import java.awt

Retrieve JTextField text value

瘦欲@ 提交于 2019-12-23 04:24:29
问题 I'm trying to retrieve the text value from a JTextField but first I need to cast a component object (java.awt.Component) to a JTextFiel... mi code is like this Component[] x = this.getComponents(); for(int i = 0; i < x.length; i++) { if (x[i] instanceof JTextComponent) { //retrieve text...something like //(JTextField)x[i].getText(); } } I'm doing this because I know all the controls of mi page are in "x" (JLabels and JTextField) but they are Components and that's why i'm making the cast to

Using OO Observer pattern without updating object from which change originated

扶醉桌前 提交于 2019-12-23 02:30:47
问题 I'm building an application which contains a GUI and a Model. I'm using the Observer pattern (using java's built in interfaces) to update the GUI when fields in the model are changed. This is generally working fine, but I have a situation in which a particular String variable in the model (specifically the url of a file) can be changed by two separate JTextFields (swing) the contents of which actually reflects the value of the model variable in question. The issue I am having comes from the

How to create a KeyEvent

感情迁移 提交于 2019-12-22 17:56:22
问题 When i create the KeyListener , it requires the following fields: public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } When i put System.out.println(e) into the keyPressed method, though, it returns this when i press the enter key: java.awt.event.KeyEvent[KEY_PRESSED,keyCode=10,keyText=?,keyChar=?,keyLocation=KEY_LOCATION_STANDARD,rawCode=0,primaryLevelUnicode=0,scancode=0] on javax.swing.JButton[,1,1,100x100,alignmentX=0.0