jtextfield

How to make JPopupMenu not take focus/mouse cursor?

Hello, I show() a JPopupMenu based on what the user types in a JTextField, however, when that happens the user typing on the keyboard will no longer write into the text field, unless with the mouse clicks again on the field, thus closing the popup menu. I want, like in Eclipse and NetBeans code completion feature, that the user may sti...

What is a simple way to create a text field (or such) that only allows the user to enter ints/doubles in Java?

I am looking for a way to ensure that my text field (JTextField, JFormattedTextField) is returning a double or int rather than a string when I call .getText(). What is the best way to do this (if possible)? Thanks! badPanda :D ...

Help on writing your own javax.swing.text.Document

I'm writing a Java TextComponent where the underlying document has some structure. It is very short, basically one line. I need to be able to override the response to inserting or deleting characters in some parts of the document. My initial approach was to implement javax.swing.text.Document, but this seems to involve developing many a...

What is the easiest way to output only a certain number of digits after a decimal place in a JTextComponent (Java swing)?

I am using both JLabels and JTextFields, and need to be able to truncate my doubles to two decimal places when they are outputted to the application. What is the easiest way of doing this (preferably without switching to JFormattedTextFields)? Thanks, badPanda :D ...

Make a text field highlighted when tabbed to in NetBeans (Java)

Hi all, I'm trying to make it so when I tab to some text fields on in my JFrame the data in the text field will be highlighted. I thought I had done this in the properties before but I am not seeing the option now. Does anyone know how to do this? ...

Losing Focus From A JTextField

After I use my textfield I can't get a jpanel that click on back into focus for my keylistener. It works for the mouselistener but all other keystrokes keep being detected by the textfield not the jpanel. The panel has been setFocusable(true) and works fine until i give the textfield the keyboard focus. It's like the textfield won't rel...

Reading barcodes from Java

Hello everyone. I'm dealing with a barcode reader in my java app. The problem is that the barcode, before and after reading and sending the actual barcode, sends a return code. I've some JTextFields and when the reader reads the barcode it change the focus, and then sends another return that makes the window to close. Is it anyway to "in...

What is the regular expression for valdating a 'price' in a jtextfield

I want to validate a jtextfield as user inputs a price of some item. I have a perfectly working code which beeps and discard if user inputs some character that doesnt match the regular expression.(for regular expression "[0-9]+" it accepts any number of digits and beeps if a letter is given as input) But the problem is I want to valida...

How can I control the width of JTextFields in Java Swing?

I am trying to have several JTextFields on a single row, but I don't want them to have the same width. How can I control the width and make some of them wider than others? I want that they together take up 100% of the total width, so it would be good if I could use some kind of weigthing. I have tried with .setColumns() but it doesn't m...

get cells odf a JTable

hi how to display a row of a jtable in a from of JTextField when click on the row, ( I need this to edit the data base from the JTable ) My table model static class TableDataModel extends AbstractTableModel { private List nomColonnes; private List tableau; public TableDataModel(List nomColonnes, List tableau){ this.nomColonne...

JTextField that has inner fields or preformated format, something like the ip field in windows

I want to create a text field that will be for dates and will have dd.mm.YYYY format. Now what I want the user to type only the numbers, not the dots to. So the field would be like: _ _. _ _ . _ _ _ _ So when the user wants to type the date: 15.05.2010 for example, he will only type the numbers in the sequence 15052010. Also I would ...

Clean multiple JTextField

Hi all! 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? ...

How do i select a character in a textfield?

is it possible to select a certain character from a textfield ? Is it possible to switch their position as well? e.g. Hello is it possible to switch the position of the "H" with the "e" ? to make it "eHllo" ? ...

Using DocumentListener to update Text Field

So I am implementing DocumentListener in order to make a search text field that will perform searches as the user types. All of that is working correctly, but I recently also discovered a need to modify what the user has put into the text field. For example, I have a function that is removing any character not in the extended ascii set, ...

Returning a JTextField to editing after a warning dialog

In my application I have a JTextField that will only allow the user to fill it with input formatted in a certain way. I have a method that checks if input into the field is valid and if not it displays a dialog. After this occurs I would like the focus to return to the text field so that the user can correct there mistake and type in t...

Can I limit the length of text in a JTextField which can be painted, while still storing the full text?

I have a text field in my application. Despite it being a text field, users sometimes paste huge amounts of text into it. Additionally, other functions of the problem set large amounts in as well. Sometimes there is so much text that the JVM gets an access violation in fontmanager.dll. Oracle doesn't appear to be interested in fixing...

How to intercept keyboard strokes going to Java Swing JTextField?

The JTextField is a calculator display initialized to zero and it is bad form to display a decimal number with a leading 0 like 0123 or 00123. The numeric buttons (0..9) in a NetBeans Swing JFrame use append() [below] to drop the leading zeros, but the user may prefer the keyboard to a mouse, and non-numeric characters also need to be ha...

automatic font resize

Hello, How can I find out, if a text in a JTextField is larger than visible area of these JTextField, so that I can change the font size? Thx for any help. Sincerely Christian ...

problem subclassing JTextField: initial text value is not displayed

I need a JTextField that only accepts positive integers as input. My implementation mostly works. As you type text into the field, the digits appear and non-digits do not appear. But there is a problem with the constructor's "text" argument. If I pass a String that contains the String representation of a positive integer, I would exp...

capturing input from JTextInput when user doesn't press Enter

In my Swing app, I have a screen that has a bunch of JTextFields. Each JTextField uses an ActionListener's actionPerformed method to copy the user-entered text to my data model object. This method seems to only be called if the user presses Enter. How can I copy the user-entered text to my data model object if the user doesn't press E...