jtextfield

Java TextField - Custom Picture / Look

六月ゝ 毕业季﹏ 提交于 2019-12-12 01:13:18
问题 I am making a game, and i want a place where users can fill out a form suggesting ideas or bugs, but want it to look similar to the rest of the game graphics/buttons etc.. I dont know how to make custom TextFields with pictures. I want the end result to look like this: I know how to set up custom buttons and custom labels, not TextFeilds, So Can anyone tell me how to easily format a JTextFeild with an image icon or something. Thanks 回答1: What is custom about that? Are you talking about: no

print an array items in a JTextField

馋奶兔 提交于 2019-12-12 00:49:12
问题 I have an application of java swing . my purpose to print the elements of a an array into a JTextField but when I press a jbutton to do that I get the following exception Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Main extends JFrame implements ActionListener { /** * @param args the command line arguments */ JTextField jtext; JPanel panel; public Main() { jtext = new

How to add JTextField on a JButton just by clicking?

本秂侑毒 提交于 2019-12-11 21:24:43
问题 So I'm making something similar to tic-tac-toe using swing. I made a GridLayout and 9 buttons, and now i want one of my jbuttons to show the jtextfield when i click on it? I tried using MouseListener, but didn't manage to find a solution that way. Any suggestions? 回答1: You can create a custom button. One way is to use a CardLayout for the button and add a JTextField and a JLabel to it. In the ActionListener of the button, if the button is pressed, you show the text field and disable the

JTextField ActionListener in GridBagLayout

你说的曾经没有我的故事 提交于 2019-12-11 20:38:32
问题 I am having troubles adding an actionlistener to my JTextField. I need to get the text entered from the user into a string so i can work with it. Can anyone tell me what im doing wrong or how i should do it. Here is the code: public void actionPerformed(ActionEvent e) { //Execute when button is pressed JFrame frame = new JFrame("Value Bet"); frame.setVisible(true); frame.setSize(500,300); GridBagLayout layout = new GridBagLayout(); frame.setLayout(layout); GridBagConstraints c = new

how to pass textfield from main class to another class

≯℡__Kan透↙ 提交于 2019-12-11 19:19:49
问题 How to pass the textfield from main class pri to CounterTask1 class. Below program is an example. Real program contains similar construction. In CounterTask1 class the textfield add with another string.If click print button it should print textfield in terminal. Advance Thanks. import java.io.*; import javax.swing.*; import java.awt.event.*; import javax.swing.SwingWorker; import java.util.List; public class pri { JFrame Frame1 = new JFrame(); JLabel SourceLabel1 = new JLabel("Source Name");

Java Swing variable not incrementing

本小妞迷上赌 提交于 2019-12-11 17:52:59
问题 The assignment I am working on requires me to build an interface that controls and tracks a train. I used an array of strings to hold on the stations. I then tried using a JTextField to display the station the train is currently at. Whenever the train leaves station, I wanted a counter 'journey' to increment so that the next station would display. However, it's not working. I'm assuming that the problem isn't to do with the variable not incrementing but rather the JTextField not updating, but

I'm trying to set JTextField under JLabel

与世无争的帅哥 提交于 2019-12-11 14:06:26
问题 I'm trying to put the text field under the JLabel . Currently, the text field is displayed on the same line. It should be below and centered. I need assistance. package Gui; import javax.swing.*; import java.awt.*; import java.awt.GridLayout; public class ShowGridLayout extends JFrame { public ShowGridLayout() { // Set GridLayout, 3 rows, 2 columns, and gaps 5 between // components horizontally and vertically setLayout(new GridLayout(3, 2, 5, 5)); // Add labels and text fields to the frame

set jtextfield textlimit and uppercase at same time

房东的猫 提交于 2019-12-11 13:59:27
问题 I Have a couple jtextfield in my app and I want to put one of them that allow upper and lowcase and also put the limit of number of character that can be introduce into the jtextfield. I have to separe class, one to put the limit and the other to put the upper or lowcase. code to the limit of jtextfield: package tester; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; public class TextLimiter extends PlainDocument {

Input text only accepts numbers

心不动则不痛 提交于 2019-12-11 13:50:48
问题 I desinged a little swing GUI that has some JTextFields, but it has a validateVariables method that has to validate all the fields that are inside the interface, there's one JTextField called (IP) must accept only int Variables how can i set it up like that? P.S the JTextfield was created it in netbeans with the palete tool. 回答1: This is the javadoc of JTextField http://docs.oracle.com/javase/7/docs/api/javax/swing/JTextField.html There is an example public class UpperCaseField extends

Instantiating array in a for loop to create JTextFields

爱⌒轻易说出口 提交于 2019-12-11 13:12:12
问题 I need to use a forloop and the text_fields instance variable to instantiate each text field, make it a listener, and add it to the applet. The text_fields variable is an array which has a max number of arrays of 2. Container c = getContentPane(); c.setLayout(new FlowLayout()); int i = 0; for (i = 0; i < FIELDS; i++) { THIS IS WHERE I DON'T KNOW WHAT TO WRITE. i need to instantiate the arrays, make them listeners and add them to the applet. } 回答1: It's unclear is FIELDS is your JTextField