JTextField 1 « JTextField « Java Swing Q&A





1. How to make JTextField expand with a BorderLayout (Java)    stackoverflow.com

I have a Java program, in which, I'm using a JTextField, but if i don't specify a default size, it'll have the width 0. I'm inserting it in a BorderLayout, so ...

2. setBorder on JTextField does not work ? or does it?    stackoverflow.com

The code is like this:

JTextField txt = new JTextField();
txt.setBorder(BorderFactory.createMatteBorder(2,2,2,2,Color.red));
However the text field is ignoring my call to setBorder. No changes whatsoever. I were to replace it with a JLabel (for instance)
JLabel txt ...

3. Clean multiple JTextField    stackoverflow.com

I was wondering about how to clean multiple JTextField in a Java applicatio, without setting the text with an empty string for each field. Any suggestions?

4. how to grab user edition from numerous swing components?    stackoverflow.com

I have a JFrame with a bunch of different JTextField and so on. How to collect data entered by user, without setting actions for each of this components? Note: I create this ...

5. Implementing Java2SAutoTextField to a JtextField    stackoverflow.com

1) I was able to add a JTextField to the JFrame, and I initialized the class Java2sAutoTextField as given in Auto Complete JTextField (Swing / AWT / SWT / ...

6. Java JTextfields    stackoverflow.com

Just a quick question, How do i ensure my JtextField only accepts numeric values? I want it to to diplsy an error message if the user entered anything else thank you

7. how to set next token to its corresponding jtextfeild    stackoverflow.com

I am reading a CSV file token by token so that each token belong to a jtextfeild how to do because it shows last token in jtextfeild

while(st.hasMoreTokens()){
//display csv values
 String ...

8. Do I need to prepare any security procedures using a JTextField    stackoverflow.com

I have a JTextField in a GUI Java App. It's not connected to a Database so I'm not worried about SQL injection or anything like that, but I wonder if I ...

9. JTextField equals another JTextField    stackoverflow.com

I have mentioned within the code below what I am looking for: About 17 rows from the bottom.

public void createHotTubs()  
{  
    hotTubs = new ...





10. Customizing JTextField    stackoverflow.com

I would like to know how to customize the ui of a jtextfield so I could create rounded rectangular border without the document going outside the border. So far I think I ...

11. Decorating a JTextField with an image and hint    stackoverflow.com

I'm trying to create some nicer looking JTextFields with an image and a hint. To do this I made a decorator that overrides the paintComponent method. The reason I used a ...

12. Incompatible types in java    stackoverflow.com

I am trying to take a String from a JTextField using getText and apply it to the method SearchString but i am presented with the error Incompatible Types i cannot see anything ...

13. Use JTextField to List items    stackoverflow.com

I'm not too familiar with Java GUI programming, and I wanted to do something where I have a loop that spits out a list of stuff and have the JTextField render ...

14. Can't make JTextField invisible at startup    forums.netbeans.org

Under the textfield properties there's no visible setting.. i know you can set it in the code with JTextField.visible(false), but how do i get it to do it at startup? I ...

15. Retrieving a table from jTextField    forums.netbeans.org

I have two jTextfield on my form which prompts user to Enter the name of a subject which in turn connotes to a table. I need to get the name of ...

16. [platform-dev] code completion for jtextfields    forums.netbeans.org

Hello, I had a simple auto-complete implementation for my textfields that I'd like to replace with the same code completion i now provide in the plain text editor (re-use). How could I do it? -- Regards, K. Gabriele --- unchanged since 25/1/10 --- P.S. Unless a notification (LON), please reply either with an answer OR with " ACK" appended to this ...





17. JTextField    coderanch.com

This sort of field is often known as "formatted" or "validated", depending on whether the checking is done for every keystroke or only when the field is moved out of/submitted. However, I have almost a personal crusade against such fields. I absolutely hate fields which limit the input to what the programmer or designer thought might be entered, especially if they ...

18. TextListener in JTextField ???    coderanch.com

Let me make sure I understand: you are saying that I can add an InputMethodListener to my textfield and then implement inputMethodTextChanged(). I can check the source of the event, which will notify me which textfield had changed value. In doing so, this listener will notify me only when the text value has changed, not when the textfield has only received ...

19. Extending JTextField    coderanch.com

Hi Patrick, When you start extending Swing components you should make use of the document listener instead of looking for key strokes. If you do that then you can easily make any TextField for any new application. Start with the following class. class MptTextField extends JTextField { public MptTextField( String defVal, int size ) { super( defVal, size ); } protected ...

20. JtextField----URGENT!!!!!!    coderanch.com

21. Setting attributes of a group of JTextFields    coderanch.com

Here's some code I wrote to go through the components on a JPanel. This might help. public JPanel fillSitePanel (JPanel _jp, SiteBean _site){ JPanel jp = _jp; SiteBean site = _site; Object [] c = jp.getComponents(); // LOOP THRU THE COMPONENTS ON THE SITE PANEL for (int i = 0; i < c.length; i++) { // PICK OUT THE TEXTFIELDS ON ...

22. JTextField    coderanch.com

Jennifer, Here's a code snippet that I hope will help you out with your problem with text field masks. I'm not sure how you want to handle storing 0's if nothing is entered. Perhaps you could initially set the text field with 5 zeros?? JTextField yourTextField = new JTextField("00000"); Notes: import javax.swing.text.PlainDocument; //Create the document: NumberDocument yourDoc = new NumberDocument(); // ...

23. JTextField    coderanch.com

I have an application that enables/disables fields on a JFrame form. Upon startup the JTextField are disabled using: jtf.setEnabled(false); Once needed the field is enabled using: jtf.setEnabled(true); The problem I am experiencing is that the first time the text field is enabled, I cannot see the highlight or the cursor. I can "pretend" to highlight the text and am able to ...

24. JTextFields not allowing entry?    coderanch.com

Hi. I am having a hard time figuring out something. When I run my application, and bring in information from the AS400, I want to key some text into one of my text fields. The problem is, whenever I try to key something, nothing shows up. The only way I can key into a field is if I hold down the ...

25. JTextField    coderanch.com

26. JTextField changed, last to know    coderanch.com

27. JTextField    coderanch.com

hi, i hv some JTextField(jtf)s in which i hv some integer values. i want tht just by using "backsapce key" whatever value i delete that should get stored in that value even without pressing "enter" key. i am not able to acheive this by actionPerfomred neither by keyListener. pl guide wth some egs. Also i want that frm anywhere i should ...

28. JTextField    coderanch.com

29. JTextField    coderanch.com

30. JTextField    coderanch.com

31. about JTextField    coderanch.com

32. JTextField    coderanch.com

i have 3 JTextFields A, B and C. these textfields require integer values to be entered.what i want to do is when a value is entered in textfield A and textfield B i want to automatically calculate the sum of the two values entered and display this value in textfield c. can i do this?? how??

33. JTextField    coderanch.com

34. JtextField Issue    coderanch.com

35. JTextField    coderanch.com

37. JTextField    coderanch.com

Hello, Just go through the below scenario and suggest me to solve it. I developed a frame which consists of two textfields. These are of JTextField object types. It also consists of two buttons 'Next' and 'Report' of type JButton. One textfield will read a question from a .txt file and the question will be displayed on the text field. The ...

38. jtextfield    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; public class CaretTest { public static void main(String[] args) { String[] text = { "caret position", "test", "in progress", "the end" }; JTextField[] tf = new JTextField[text.length]; FocusListener l = new FocusAdapter() { public void focusGained(FocusEvent e) { JTextField tf = (JTextField)e.getSource(); int endPos = tf.getDocument().getLength(); tf.setCaretPosition(endPos); } }; JPanel panel = new ...

39. JTextField    coderanch.com

40. JTextfield    coderanch.com

try this import javax.swing.*; import java.awt.*; import java.awt.event.*; class Testing extends JFrame implements ActionListener { JTextField tf1 = new JTextField(10); JTextField tf2 = new JTextField(10); public Testing() { setLocation(300,200); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel jp = new JPanel(); tf1.addActionListener(this); tf2.addActionListener(this); jp.add(tf1); jp.add(tf2); getContentPane().add(jp); pack(); } public void actionPerformed(ActionEvent ae) { if(ae.getSource() == tf2) { JOptionPane.showMessageDialog(this,"Textfield 1 = "+tf1.getText()+ "\nTextfield 2 = "+tf2.getText()); } else ...

41. JTextField with hint list    coderanch.com

42. Duplicates from JTextField    coderanch.com

Hi I have been pulling my hair out with this problem. Every time i use a JTextField instead of adding one thing, it adds the string typed into to the object set in action listener but then it adds an empty object. This has had me baffled for over a week. I have tested the Add methods in the calling class ...

43. JTextField.setSize()?    coderanch.com

44. Autoscrolling in a JTextField    coderanch.com

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

46. Multiple table records in jtextfields    coderanch.com

Hi all! Is it possible to have multiple table records vertically aligned, displayed in jtextfields and contained in a jpanel? It looks something like a jtable in which multiple records are displayed one-by-one vertically but I want to control the spacing, position and add some data which are not fields in the table.

47. Intercepting control-X in a JTextField    coderanch.com

I'm developing an app where I've used Swing's undo framework to allow the user to undo/redo significant actions. There are various JTextFields in the app, and if the user uses the application's Edit -> Cut menu item (for example), an UndoableEdit is invoked, and the text is cut; the user can easily undo the cut afterwards. Standard stuff. The problem is ...

48. JTextfield    coderanch.com

49. jTextfield help    coderanch.com

50. regarding JTextField    coderanch.com

51. Mask JTextField 1.3    coderanch.com

You can do one of two things that I know of off the top of my head. One is use a keylistener on the textfield and in your method KeyReleased, validate the last character pressed to see if its consistent with the mask, i.e. if the mask is (XXX) XXX-XXXX, then when they enter the 10th character, make sure its a ...

52. JTextField    coderanch.com

53. Multilingual support by JTextField    coderanch.com

Hi, In our application which supports English and Arabic both, I want to enter arabic numbers in a textfield. I have set up my machine so that I can switch my keyboard output between english or arabic! So when I select Arabic as keyboard output and enter arabic alphabets it does type them in a textfield. But when I try to ...

54. JTextField with automatic completion?    coderanch.com

we must be talking about different descriptions of autocomplete. I'm talking about where you type in a letter and a popup displays with the matches of all words starting with that letter. Type in the next letter and the number of matches decreases etc. Eventually you select the word/entry you want, from the popup, and this is entered into the textfield. ...

55. JTextField.setEditable is not working    coderanch.com

56. JTextField in JInternalFrame    coderanch.com

57. JTextField    coderanch.com

58. JTextfield getColumns() method    coderanch.com

hi im trying to get information from a textfield for how many columns in the text field are currently visible. for example, if i open a certain window which contains a text field, so i would like to know, how many chars can be written to the textfield until not all of them can be seen, and of course when i ...

60. print a Random to jTextField    coderanch.com

61. JTextField in JScrollPane    coderanch.com

Trying to learn Swing GUI again and have a problem. When the following program displays its window initially, there is a text field in the middle full of characters. If I add a character to it, the scroll bar appears and obscures the text in the text field. I've tried some changes to the GridBagConstraints that give the text field more ...

62. Regarding JTextField    coderanch.com

64. JTextField    coderanch.com

hi everyone I need help for this project: Write an application that controls the movements of a robot rat via a control panel. The robot rat will move about a "floor" represented by a two-dimensional boolean array. The robot rat has a pen attached to its tail. As the robot rat moves about the floor it will leave a mark if ...

65. JTextField swings    coderanch.com

66. Help on JTextField    coderanch.com

68. How to get variable from JTextField()    coderanch.com

69. Setting JTextFields    coderanch.com

Here is a sample code that doesn't work: //Test import javax.swing.*; import java.awt.*; import java.awt.event.*; public class test extends JFrame implements ActionListener { Container pane; JButton button; JTextField textField; public test() { super("Test"); setSize(200,200); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); pane = getContentPane(); pane.setLayout(null); setVisible(true); addWidgets(); } private void addWidgets() { JButton button = new JButton("Hit Me"); JTextField textField = new JTextField(""); button.addActionListener(this); pane.add(textField); textField.reshape(1, ...

70. JTextField    coderanch.com

71. JTextField    coderanch.com

// --- the result of getText is always a string (or, maybe null, I'm not sure --- // String fullString = jTextField.getText(); // --- usually, it's best to trim the string so that you don't get database queries such as: find all sales where the salesperson is a space. This is wrong and hard to trouble-shoot. --- // String trimmedString = ...

72. better performance with a custom jtextfield    coderanch.com

I originally posted this on the java.sun forums, http://forums.sun.com/thread.jspa?threadID=5361214&tstart=45, but was looking for a bit more help. Basically I'm drawing a custom jtextfield with a gradient background. The problem comes when text is actually being put into the textfield the cpu jumps and the performance is awful. Im assuming its from the textfield being redrawn with the gradient each time a ...

73. Reg. Validatin JTextFields    coderanch.com

Mohan, In future please do not use big fonts as it makes the post hard to read. If you want to draw attention to a portion of your post, you can use the italics or bold. The setColumn() method is used to control the visible width of the text field. Check out this example which should point you to how you ...

74. Jtextfield starting point for writing    coderanch.com

75. Using JTextfields in a JTabbedPane    coderanch.com

Hi Rob I have the following code below. I am pulling data from the arraylist eloc, and trying to place the data in textfields in the JTabbedPane's txtTotalWater box.. public Analysis(String sourcepath, String sourcefile, ArrayList elist) { super("Entity Analysis Overview"); setSize(WIDTH, HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); source = sourcepath; count = read_location(source); int loc_index = eloc.size(); String temp; for(int index = 0; index < ...

76. Using JTextFields in JTabbedPane    coderanch.com

Hi I created a JTabbedPane GUI application that contains textfields. I am trying to display data from a Arraylist in the JTextFields. Can anyone provide some insight into displaying data into JTextFields, in JTabbedPane's ??? Thanks public Analysis(String sourcepath, String sourcefile, ArrayList elist) { super("Entity Analysis Overview"); setSize(WIDTH, HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); source = sourcepath; count = read_location(source); int loc_index = eloc.size(); String ...

77. Jtextfield    coderanch.com

78. datetime on a jtextfield    coderanch.com

79. need help in applying inputverifer to jtextfield    coderanch.com

[b]1.facing problem in applying input verifier to JTextfield[/b] main class VerifierTest import java.awt.*; import java.util.*; import java.awt.event.*; import javax.swing.*; public class VerifierTest extends JFrame { JDialog p; public VerifierTest() { JTextField tf1 = new JTextField ("Type \"pass\" here"); getContentPane().add (tf1, BorderLayout.NORTH); tf1.setInputVerifier(new NotEmptyValidator(parent, tf1, "Field cannot be null.")); JTextField tf2 = new JTextField ("TextField2"); getContentPane().add (tf2, BorderLayout.SOUTH); WindowListener l = new ...

81. about jtextfield auto suggest    coderanch.com

hi. im currently creating a JTextField that will be able to auto suggest words that are existing inside a vector.. i currently have this.. public class SuggestTextField extends JTextField { public SuggestTextField() { final Vector items = new Vector(); final JTextField field = this; addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { items.add(field.getText()); //adds to the vector the item previously entered ...

83. StringBuffer + JTextField    coderanch.com

84. isEnabled() method for Jtextfield    coderanch.com

85. Storing JTextField to variable    coderanch.com

Hello, I made this GUI using netbeans and I was wondering, how can I store the JTextFields to a local variable? /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * AddressEntryGUI.java * * Created on Oct 20, 2011, 10:46:01 AM */ package address.gui; import address.gui.event.AddressEntryEventHandler; import javax.swing.JTextField; /** * ...

87. how to additem in jtextfield    java-forums.org

88. JTextField    java-forums.org

class MyDocumentListener implements DocumentListener { public int x,y; public MyDocumentListener(int posx,int posy) { x=posx; y=posy; } public void insertUpdate(DocumentEvent e) { try { if (cellCheck(x,y)) { errore=false; tf[x][y].setBackground(Color.LIGHT_GRAY); } else { JOptionPane.showMessageDialog(null, "error"); error=true; tf[x][y].setBackground(Color.RED); //it works tf[x][y].select(0,1); //doesn't works } } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(null, "error"); errore=true; tf[x][y].setBackground(Color.RED); } } {

89. Write-only JTextField?    java-forums.org

Hello. My question today is, hopefully, a simple one: is there an easy way to have a JTextField (or JTextArea or any simillar component) that only allows to input text but not modify in any way what's already been entered? The behaviour I'd like to have is that once the user has entered a character, he can neither delete it, nor ...

90. ArrayIndexOutOfBoundsException - possible bug in JTextField?    java-forums.org

Hey all, I keep getting a rather weird glitch: Java Code: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 10 at sun.font.FontDesignMetrics.charsWidth(FontDesignMetrics.java:492) at javax.swing.text.Utilities.getTabbedTextOffset(Utilities.java:381) at javax.swing.text.Utilities.getTabbedTextOffset(Utilities.java:302) at javax.swing.text.Utilities.getTabbedTextOffset(Utilities.java:286) at javax.swing.text.PlainView.viewToModel(PlainView.java:403) at javax.swing.text.FieldView.viewToModel(FieldView.java:263) at javax.swing.plaf.basic.BasicTextUI$RootView.viewToModel(BasicTextUI.java:1540) at javax.swing.plaf.basic.BasicTextUI.viewToModel(BasicTextUI.java:1089) at javax.swing.text.DefaultCaret.positionCaret(DefaultCaret.java:292) at javax.swing.text.DefaultCaret.adjustCaret(DefaultCaret.java:497) at javax.swing.text.DefaultCaret.adjustCaretAndFocus(DefaultCaret.java:485) at javax.swing.text.DefaultCaret.mousePressed(DefaultCaret.java:475) at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263) at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:262) at java.awt.Component.processMouseEvent(Component.java:6260) at javax.swing.JComponent.processMouseEvent(JComponent.java:3255) at java.awt.Component.processEvent(Component.java:6028) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574) ...

91. JTextField setColor()    java-forums.org

I am building a game GUI, and I have uneditable text fields that display your current health and status. These text fields will change color depending on your health percent and status. The errors I get are: Java Code: /tmp/jc_12285/GameGUI.java:103: class, interface, or enum expected public void statusColor() ^ /tmp/jc_12285/GameGUI.java:110: class, interface, or enum expected statusDisplay.setColor(Color.Green); ^ /tmp/jc_12285/GameGUI.java:112: class, interface, or ...

92. JTextField loop 2x for-loop WEIRD!    java-forums.org

Not sure why this is happening, but I am trying to make a simple loop function that will create some JTextFields for some project I have to do. I am not sure why, but the very LAST textField is not being added to the stage. I have tested it. It is definitely added, and It should be there, but for some ...

93. public jTextField ?    java-forums.org

Ok simple question! I have a swing jFrame in a netbeans java application project and a jTextField inside of it. Is there any possible way of retrieving the text from the textField using another class? Obviously i cannot do that because the textField is declared private in swing awt but i was wondering if there is any way around it. Thanks ...

94. [SOLVED] JtextField alignments issue.......?    java-forums.org

Hi Members, Im using jtextField to display some description message, but when the 'message extends greater than the textfield size, it automatically gets aligned from 'Right to Left', but i need to show it from 'Left to Right' aligned. I also tried 'JtextField.setHorizontalAlignment(JTextField.LEFT );' but it is not working when the message size is greater than textfield size. Looking forward for ...

95. jTextField Simpe Addition - how to ? - Netbeans 6.0    java-forums.org

I did the same. but error occurs while printing Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: " 2" at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:447) at java.lang.Integer.parseInt(Integer.java:497) at NewJFrame.jButton1ActionPerformed(NewJFrame.java:9 7) at NewJFrame.access$000(NewJFrame.java:11) at NewJFrame$1.actionPerformed(NewJFrame.java:40) at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236) at java.awt.Component.processMouseEvent(Component.jav a:6038) at javax.swing.JComponent.processMouseEvent(JComponen t.java:3260) at java.awt.Component.processEvent(Component.java:580 3) at java.awt.Container.processEvent(Container.java:205 8) at ...

96. JTextfield Ajax Searching    java-forums.org

AJAX stands for Asynchronous Javascript and is a web applications trick for fooling users into thinking that they are getting their pages refreshed without a submit to the server. It has nothing to do with a JTextfield because that is a swing component which cannot be used in web applications. You are going to have to implement it all using Java. ...

97. jtextfield backcolor    java-forums.org

98. datetime on a jtextfield    java-forums.org

99. JTextField method numberic    java-forums.org

Hi In the following code, I have a problem with JTextField method. The problem is how I can get the numbers that the user enters in the fields. Actually, I have tried many times to fix the problem but I couldn't Java Code: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Postage extends JApplet implements ActionListener{ private JLabel lengthLabel; private JLabel ...

100. JTextField and SimpleDateFormat    java-forums.org

//[b]INPUT:[/b] 5/25/2010 //[b]EXPECTED OUTPUT:[/b] 2010-05-25 import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.*; import java.text.*; public class TextDate extends JFrame { JTextField input = new JTextField(); JTextField output = new JTextField(); JPanel p1 = new JPanel(); JButton b1 = new JButton("CLICK"); public TextDate() { this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLayout(new BorderLayout()); this.add(p1, BorderLayout.CENTER); p1.setLayout(new GridLayout(2,2)); p1.add(input); p1.add(b1); p1.add(output); pack(); b1.addActionListener(new ButtonClick()); } public static void ...