jtextfield

Java Swing: JButton creates new JTextField(s)

有些话、适合烂在心里 提交于 2019-12-08 07:26:54
问题 Hello :) I am beginner in Java Swing and I can't google solution for my problem. I have a JPanel and want to add JTextField(s) dynamically after pressing a JButton. And how can I getText() from them later? My code, commented part isn't working properly. Variable 'counter' counts how many fields I have in panel. public class AppPanel extends JPanel { private JTextField tfData[]; private JButton btAdd; private int counter = 1; public AppPanel() { setLayout(null); //tfData[counter] = new

Java - Program which remembers/saves entered fields

六眼飞鱼酱① 提交于 2019-12-08 04:18:34
问题 I have a program that uses three JTextField fields as the main data entry fields. I want to have it so that when the user terminates the program and then opens it again, their last entry will still be in the fields. How could I achieve this? Would I need some sort of database or is there a simpler way? 回答1: the simplest way to achieve this is to add a listener to the text field and use the java preferences api: textField = new JTextField(); // set document listener textField.getDocument()

JTextField's setText method doesn't work from a KeyListener

落爺英雄遲暮 提交于 2019-12-07 21:50:51
问题 I'm puzzled as to why a JTextField doesn't seem to just "clear out" by using the setText("") method on it, when this is coming from a KeyListener. It works fine from an ActionListener, except that, most amazingly, if the KeyListener method tries to invoke the ActionListener method, with a dummy action event (created on the fly as a simple test), it still leaves the typed text in place. In other words, when you run it from the command line, if you type, for example, a "3" into the field, you

How to make a Round Rectangle JTextField?

懵懂的女人 提交于 2019-12-07 15:02:36
问题 I want to make a round rectangle JTextField. I write a sub class of AbstractBorder to realize it.But I run into some problems. My requirement is: What I get is: My code is : import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing

Java swing 1.6 Textinput like firefox bar

此生再无相见时 提交于 2019-12-07 10:20:54
问题 I would like to create a textwidget/component wich looks like the firefox address bar. I mean a Textfield wich allows me to place little Buttons inside the field (e.g. cancel/reload/...) I tried customizing a JLayeredPane, by creating a custom layout manager which maximizes the Textfield, and places the remainder from right to left. My problem is that this gave painting issues, I would not always see the items I added over the textfield. This might be Jython related, I try suppling java.lang

How can I get the length of a JTextField's contents as the user types?

你说的曾经没有我的故事 提交于 2019-12-06 23:14:27
问题 JTextField has a keyTyped event but it seems that at the time it fires the contents of the cell have not yet changed. Because of that .length() is always wrong if read here. There must be a simple way of getting the length as it appears to the user after a key stroke? 回答1: This is probably not the optimal way (and it's been a while), but in the past, I have added a DocumentListener to the JTextField and on any of the events (insert, update, remove) I: evt.getDocument().getLength() Which

Changing JTextField's text while iterating or inside a loop [duplicate]

会有一股神秘感。 提交于 2019-12-06 16:00:55
问题 This question already has answers here : updating a JProgressBar while processing (2 answers) Closed 6 years ago . Let's say I have a JTextField "status" and I'm running this code: status = new JTextField(50); add(status); for (int i=0; i<10000; i++) { status.setText("bla bla - "+ i); System.out.println("bla bla - "+ i); } My problem is that right now while the loop is running nothing happened in the JTextField's text and only when the loop end the label is "bla bla - 10000". I want to make

Using OO Observer pattern without updating object from which change originated

狂风中的少年 提交于 2019-12-06 15:32:14
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 fact that an change in one of these JTextFields needs to cause an update to the state of the model, and

Java- How to add more textfields by clicking a button?

一世执手 提交于 2019-12-06 13:16:47
问题 I have created a frame in Java which has some textfields and buttons in it. Assuming that user wants more textfields (for example to add more data), I want to put a button and when a user clicks the button , then a new textfield should appear. then user can fill data in it and again by clicking that button another textfield should appear. How can I do this ? What code I need to write for the button to show more and more text fields by clicking button? Thank you ! 回答1: It would be wise that

Why is iText's PdfWriter printing JTextFields black when exported as a runnable jar?

怎甘沉沦 提交于 2019-12-06 12:25:35
I hava got a strange conundrum. I am currently trying to make a Runnable Jar of an Eclipse project I'm working on that has a number of JTextField's and JFormattedTextField's all nicely arranged in JPanel's. I am then taking these JPanel's and printing them out use iText's nice PdfWriter. The issue is this: In Eclipse, this prints out just fine. When I export my project into a runnable jar, I get the following: All of those black rectangles are where my JTextField's and JFormattedTextField's are located. Does anyone have any idea what may be causing this? This is how I am printing things out,