jtextfield

How can I add single character to the JTextField by pressing the JButton

一笑奈何 提交于 2019-12-12 16:47:24
问题 I am creating a simple program, which will allow me to add single character to JTextField by pressing JButton . In this program, I have an array of string named words & I have a String name word , which is allowing me to choose words randomly from the array of words. I am using a for loop to draw the JTextFields . Number of the JTextField depends on the length of the word import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.text.*; import

JTextField - setColumns() method not working for me

戏子无情 提交于 2019-12-12 12:12:54
问题 my problem is that my JTextField -setColumns(int) "field1.setColumns(5);" ...doesn't work. I'm guessing its a layout manager problem. However, I'm learning from an exercise book. The only layouts I know are flowLayout, borderLayout and gridlayout. To explain this code in short, whenever "field2" triggers an ActionEvent (by pressing the enter key) "field1" should change size. I've placed a "System.out.println("ActionEvent detected") in the "actionPerformed" to prove an actionevent is being

Performing a certain task after pressing “ctrl” + “alt” + “backspace”

元气小坏坏 提交于 2019-12-12 11:22:08
问题 How do I code it when I want to perform something. Let's say that the focus on a JTextField and a messagebox will pop up when the user pressed ctrl + alt + backspace at the same time. 回答1: An example with key bindings: import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.*; public class JTextFieldMagic { public static final String CTRL_ALT_BACK_SPACE = "ctrlAltBackspace"; public static void main(String[] args) { JTextField field = new JTextField(10); int

Java swing getting input from a JTextField

天涯浪子 提交于 2019-12-12 09:12:24
问题 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

Implementing Java2SAutoTextField to a JtextField

时光怂恿深爱的人放手 提交于 2019-12-12 09:01:40
问题 1) I was able to add a JTextField to the JFrame , and I initialized the class Java2sAutoTextField as given in Auto Complete JTextField (Swing / AWT / SWT / JFace forum at JavaRanch). 2) I initialized the list and field inside the JFrame constructor, as shown below. List possible = new ArrayList(); possible.add("Austria"); possible.add("Italy"); possible.add("Croatia"); possible.add("Hungary"); Java2sAutoTextField autoCompleter = new Java2sAutoTextField(possible); 3) The problem that arises is

JTextField setEnabled vs setEditable

廉价感情. 提交于 2019-12-12 08:25:40
问题 What is the difference between JTextField.setEnabled() and JTextField.setEditable() ? In my code I have an Instance of a class inherited from JTextField . But when I set its property setEnabled(false) I can still edit and process its contents in my program. However when I set its property setEditable(false) I can no longer edit its text. If it is so. Then what is the purpose of setEnabled() property here? My Code for inherited class is: private static class CCField extends JTextField{ private

Java Swing rounded border for Jtextfield

天大地大妈咪最大 提交于 2019-12-12 08:12:01
问题 When I do : LineBorder lineBorder =new LineBorder(Color.white, 8, true); jTextField2.setBorder(lineBorder ); I get this result like: How can I have rounded borders without the squared corners visible and the text half cut ? Thank you very much. Best regards 回答1: You can override JTextFiled build your own Rounded corner JTextField . You have to override it's paintComponent() , paintBorder() , and contains() methods. You need to draw roundRect as the shape of text field. Example: public class

JTable - Selected Row click event

。_饼干妹妹 提交于 2019-12-12 07:12:13
问题 I have a Jtable that is populated with a linkedlist through an AbstractTableModel. What I want to do is when I click (left-mouse click) on a row in the JTable, the linkedlist is search (in this case it contains movie titles) and displays the values in the linked list in Jtextboxes How do I do this? Here is the code GUI_g: http://pastebin.com/J3qtjn8J ProgramTableModel: http://pastebin.com/Dwkc9Cz3 Processing: http://pastebin.com/qHnkvCbr Main: http://pastebin.com/K4yGYX9H My guess it retrieve

Is it possible that after typing a value in jTextfield it will automatically press without using jButton?

痴心易碎 提交于 2019-12-12 07:01:53
问题 Is it possible that after typing a value in jTextfield it will automatically press without using jButton? i dont know if its possible.. well ill be using it in my barcode scanner after the scan and display the values the jTextfield will automatically receive and start the query on database 回答1: The answer depends on your definition of "press". In my experience, the expectations are, when the barcode is scanned, the action will be performed without the user having to do anything extra Based on

My setText isn't updating my JTextField?

对着背影说爱祢 提交于 2019-12-12 06:46:26
问题 So I'm missing something here, but I can't get my setAttributes method to update the agility text field like it's supposed to. The class that calls the method and the call works fine passing in the needed values as seen by the system.out.println(agility). However in just the line below I try to set the agilityAmount txtfield and it doesn't display. What am I doing wrong? class GraphicalInterface extends JFrame implements Runnable, KeyListener { GraphicalInterface() { } JFrame mainwindow; /