jtextfield

java swing display search result in a popup under JTextField “like facebook search”

爷,独闯天下 提交于 2019-12-10 10:59:45
问题 I'm trying to simulate in java swing the same search results preview on facebook, but in java I suppose it'll gonna be : JTextField : the user input goes here JList : containing JList of JPanels ( results ) a popup or some container to hold the JList The problem is, I couldn't manage how to display a popup right under the JTextField, I tried swingx autocomplete, editable combo box , glazedlists ... but it's not giving me good results Can anyone help me please ? 回答1: When specifying the point

Adding textfield to Graphics in java

瘦欲@ 提交于 2019-12-10 03:29:09
问题 Does anyone know how to add JTextField into Graphics name bufferstrategy.getDrawGraphics ? Tryed to pain it into graphics, something like this: private JTextField Input = new JTextField(); BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3); return; } final Graphics gCommands = bs.getDrawGraphics(); Graphics gCC = bs.getDrawGraphics(); Input.requestFocus(); Input.paint(gCC); Input.setBounds(800,250, 350,20); Input.setBorder(BorderFactory.createLineBorder(Color

swing: appropriate Listener for JTextField change events

六月ゝ 毕业季﹏ 提交于 2019-12-09 15:53:59
问题 Which type of Listener do I use for listening to changed text events in a JTextField? (I should know this or be able to tell from the Javadoc but I can't seem to figure it out.) 回答1: Use the underlying document: myTextField.getDocument().addDocumentListener(); 来源: https://stackoverflow.com/questions/2165071/swing-appropriate-listener-for-jtextfield-change-events

Limiting TextField inputs

蹲街弑〆低调 提交于 2019-12-09 01:24:38
问题 I'm trying to make a textfield that limits a user input. I have this code: private void jTextField5KeyTyped(java.awt.event.KeyEvent evt) { //This limits the input: if(jTextField5.getText().length()>=2) { jTextField5.setText(jTextField5.getText().substring(0, 1)); } } It successfully limits the input. However, when I tried to press other characters on the keyboard, it changes the last character on the textfield. Any ideas to stop this? I know others will say that I should use Document(Can't

Java Swing: JButton creates new JTextField(s)

自作多情 提交于 2019-12-08 21:03:34
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 JTextField(); //tfData[counter-1].setBounds(20, 20, 250, 20); //add(tfData[counter-1]); btAdd = new JButton(

How to set a custom background color on a line in a JTextPane

。_饼干妹妹 提交于 2019-12-08 16:25:50
问题 I would like to alternate between gray and white as background from one line of my JTextPane to the next. I tried to do this by overloading the paintComponent() method and drawing the background manually according to component height an Font size but I did not succeed. Any hints? 回答1: You can use the line highlighter (here or here), written by @VonC, in response to this question. In order to highlight alternate lines you can use it as follows: public static void main(String[] args) {

Adding numbers to an arraylist from the Jtextfield

感情迁移 提交于 2019-12-08 12:48:32
问题 I am sure its very simple but this is my first java class. the user enters a number into the input Jtextfield. the Add button is supposed to add that number to the arraylist. I am having trouble figuring out how to do that exactly. Any help you can give me would be awesome import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; public class ArrayExercise extends JFrame { private final int WINDOW_WIDTH = 300; private final int WINDOW_HEIGHT = 300; private

DocumentListener interfering with my JTextField

耗尽温柔 提交于 2019-12-08 11:45:48
问题 What I am trying to do is keep the user from inputting an empty string into my input. Right now, the user is restricted to typing only numbers. However, nothing keeps them from leaving the text field blank. I want to restrict them from hitting my button to start the program when it is blank. Right now, my text field is initially left blank and the button is grayed out initially. But when I type something in, the button stays greyed. Keep in mind all this code is in the constructor. private

Java - I need to update JTextFields in a Swing GUI program [duplicate]

假如想象 提交于 2019-12-08 10:02:49
问题 This question already has answers here : WatchService for Java 6 [closed] (3 answers) Closed 6 years ago . I have a program that looks into a single Notepad file which contains information similar to: Cardiff : 3245658 Bristol : 4726485 Manchester : 4728945 These places and numbers are coming out of a automatic system, and the numbers change every 20 seconds or so. I need to create a loop(I'm guessing) so that when the numbers change, my program will look back into the notepad file and update

How to disable default textfield shortcuts in JTextField

余生长醉 提交于 2019-12-08 08:23:02
问题 I have a custom textfield class that extends the JTextField class in Swing. I need to find a way to disable the default actions for Ctrl-A (select all), Ctrl-H (backspace) etc, so that the window containing the textfield can map these shortcuts to whatever it wants. Any help would be greatly appreciated. 回答1: Okay, found the answer myself: Added the following to an initilization method of the textfield class: this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK),