jtextfield

KeyListener detecting backspace only once

倾然丶 夕夏残阳落幕 提交于 2019-12-13 05:17:56
问题 I'm making a custom textfield (drawing the text instead of using JTextField). I can type the characters in, but the backspace only clears one character. Then if I write something more, I can delete one character again. I have no idea why. KeyListener: class KeyController implements KeyListener { public void keyPressed(KeyEvent e) { if (!chat.getUsing()) { player.keyPressed(e); } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { chat.keyTyped(e); } if (e.getKeyCode() == KeyEvent.VK_ENTER) {

Flashing JTextField and JButton

徘徊边缘 提交于 2019-12-13 05:13:44
问题 //ADDING BET FIELDS setLayout(null); horseChoice = new JTextField(); horseChoice.setBounds(200, 585, 300, 20); add(horseChoice); setLayout(null); horseBet = new JTextField(); horseBet.setBounds(200, 625, 300, 20); add(horseBet); //ADDING BET BUTTON setLayout(null); bet = new JButton("Place Bet"); bet.setBounds(250, 675, 200, 50); add(bet); I am trying to create two textfields where the users can type in what they want and a button to save their input to a variable. But when I run my program,

What is the proper use of KeyListener? [closed]

给你一囗甜甜゛ 提交于 2019-12-13 05:05:17
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . So I have been working on trying to extract the data in my jTextFields and this error message keeps popping up referring to an: Exception in thread "AWT

Replace JTextField with an Image?

泪湿孤枕 提交于 2019-12-13 04:53:28
问题 I've been searching on way's to replace a JTextField with an Image & nothing comes up. Is it possible to add a jtextfield onto an image or replace on with an image? I'm using a JPanel & I am trying to put the JtextField inside the image below: 回答1: There are several ways this might be achieved... The simplest might be to use a JLabel , set it's layout manager to something BorderLayout and simply add the text field to it... JTextField field = new JTextField(); field.setOpaque(false); JLabel

Is it possible to calculate JTextFields into a JLabel as they are being typed? [closed]

北城余情 提交于 2019-12-13 04:29:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Is it possible to calculate a group of JTextFields as they are typed in and set the result to a JLabel? For Example: int iCalc = 0; JTextField x = new JTextField(); JTextField y = new JTextField(); JTextField z = new JTextField(); JLabel lCalc = new JLabel("Your total is: " + calc); As i am typing, calc gets

How to intercept keyboard strokes going to Java Swing JTextField?

随声附和 提交于 2019-12-13 02:30:28
问题 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 handled. private void append(String s) { if (newEntry) { newEntry = false; calcDisplay.setText(s); } else if (0 != Float.parseFloat(calcDisplay.getText()

Gradient textfields in panel with TitledBorder - performance issue

我是研究僧i 提交于 2019-12-13 01:49:43
问题 I have a panel with 3 inner panels that all use a TitledBorder . The third inner panel has a number of custom textfields that are painted with GradientPaint . The textfields come from a custom class that extends JTextField and uses an overriden paintComponent method along with a MouseListener , so that when mouse enters on a textfield area the gradient color slightly changes (and changes back again when mouse leaves the textfield). The problem is that the gradient color change does not

What event to use when pasting something in a JTextField?

一曲冷凌霜 提交于 2019-12-13 01:39:33
问题 I have a JTextField . I want an event to execute when I paste something inside the JTextField . What event do I need to solve my problem? 回答1: KeyListener doesn't work if you paste in text, that's why you should use DocumentListener. Check the link, it explains it very good, here's something to begin with: private DocumentListener myListener = new DocumentListener() { @Override public void changedUpdate(DocumentEvent documentEvent) { //... } ... ... } 回答2: Agree with Maroun Maroun about

make custom JTextField (JCurrencyField)

我的梦境 提交于 2019-12-13 00:52:52
问题 I making a JCurrencyField to use it in my program, I almost finished creating it but I've faced an issue. JCurrencyField is a normal JTextField but it cannot accept any character that is not a number or decimal point . and I made some specifications for this JCurrencyField: The user cannot insert more than one decimal point . . The user cannot insert more than two digits after the decimal point. The issue I've faced was not being able to insert any digits before the decimal point if there are

How to add background image to JTextField?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 18:18:41
问题 I know how to add background image to JPanel (creating ImagePanel class that extends JPanel and overload it's paintComponent() method), BUT this trick with JTextField not working properly: Displays image, but not text. So, how to add background image to JTextField properly? 回答1: You need to add the text field to the label. Something like: JTextField textField = new JTextField(10); textField.setOpaque( false ); JLabel label = new JLabel( new ImageIcon(...) ); label.setLayout( new BorderLayout(