jtextfield

Click on icon in a JTextField and clear its content

做~自己de王妃 提交于 2019-12-05 18:58:15
I am trying to create a JTextField with an image and a hint. The function of the textfield is a search field to search some books. Now, I like to go a little bit further. I would like to give the image a function. For example, if I click on the image the text in the textfield should be cleared. To achieve this implementation I created a new class and extended it with JTextField. This is the code: public class JSearchTextField extends JTextField implements FocusListener { /** * */ private static final long serialVersionUID = 1L; private String textWhenNotFocused; private Icon icon; private

Java swing 1.6 Textinput like firefox bar

江枫思渺然 提交于 2019-12-05 18:19:23
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.Integer(1) to the JLayeredPane.add . However the Layers are ordered exactly reverse to what the

Simple way to cancel user input on esc key pressed?

血红的双手。 提交于 2019-12-05 16:36:54
Is there a simple way to cancel the user input in a JTextField when key Esc is pressed ? I mean something different that a key listener and a data backup. Thanks Add a KeyListener to your JTextField: JTextField field = new JTextField.addKeyListener(yourKeyListener); where yourKeyListener could be: public class YourKeyListener implements KeyListener{ void keyPressed(KeyEvent e){ Component source = e.getSource(); if (source instanceof JTextField && e.getId() == KeyEvent.VK_ESCAPE ){ JTextField f = (JTextField) source; f.setText(""); } } } CancelAction , discussed here and shown here , is an

Korean characters are displayed as empty boxes on JTextField

允我心安 提交于 2019-12-05 16:13:37
JTextfield does not show korean charaters properly. It shows empty boxes in instead of characters. Here is the screenshot of my application. Thats because of the fonts that you used. According to this oracle document Korean letters is not supported by Lucida font. Note that of the writing systems that are generally fully supported by the JRE, the Lucida fonts do not support Chinese (Simplified), Chinese (Traditional), Japanese, and Korean. So if you use the fonts that support the korean language, it will work properly. 来源: https://stackoverflow.com/questions/42244385/korean-characters-are

How to insert a 'String' in a 'JTextField' to a specific position?

北城余情 提交于 2019-12-05 10:56:27
I want to insert a String in a JTextField . Something like- myTextField.insert(text, position); How can it be done? Is there any simple way to do this? Mohayemin You may do this- jTextField.setText("This swing."); jTextField.getDocument().insertString(5, "is", null); And jTextField will show- This is swing. 来源: https://stackoverflow.com/questions/11493508/how-to-insert-a-string-in-a-jtextfield-to-a-specific-position

Adding textfield to Graphics in java

强颜欢笑 提交于 2019-12-05 03:50:54
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.BLACK, 0)); Input.setEditable(true); Input.setBackground(getBackground()); Input.setForeground

Java, Swing: how do I set the maximum width of a JTextField?

浪子不回头ぞ 提交于 2019-12-05 02:13:32
I'm writing a custom file selection component. In my UI, first the user clicks a button, which pops a JFileChooser ; when it is closed, the absolute path of the selected file is written to a JTextField . The problem is, absolute paths are usually long, which causes the text field to enlarge, making its container too wide. I've tried this, but it didn't do anything, the text field is still too wide: fileNameTextField.setMaximumSize(new java.awt.Dimension(450, 2147483647)); Currently, when it is empty, it is already 400px long, because of GridBagConstraints attached to it. I'd like it to be like

Different font color in a JTextField

筅森魡賤 提交于 2019-12-05 01:51:42
问题 How to display a text in a JTextField ot jLabel with 2 colors. for example: 1 0 0 0 1 1 1 0 1 textField.setForeground(Color.RED ,BLUE); Positioning individual RED for example 回答1: Different font color in a JTextField You can't achieve it with JTextField instead use JEditorPane or JTextPane. Read more about How to Use Editor Panes and Text Panes Sample code using JTextPane directly from HERE import javax.swing.*; import javax.swing.text.*; import java.awt.*; public class StylesExample12 {

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

无人久伴 提交于 2019-12-04 19:17:59
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 ! It would be wise that instead of adding components to your JFrame directly, you add them to a JPanel . Though related to your

Java swing getting input from a JTextField

大憨熊 提交于 2019-12-04 18:09:39
I see something like this asked around a lot, but it hasn't answered my problem. I am fairly new at Java. I am trying to get some input from a JTextField and return it as a String so I can use it for comparison in a different class. This is what I see as an answer, I'd like to be able to use str in any other part of the class. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; public class ClassFrame extends