Results 1 to 6 of 6
Thread: Public JTextField question
- 10-24-2011, 01:06 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Public JTextField question
Hello,
I'm trying to learn Java (the basics), but I'm having a problem the book does not explain well. It is about the following:
Public JTextField variable (String JPanelText, String TextFieldText, int columns) (they call it columns in English, right? The size of the textfield)
Basically, I need to make a JPanel + JTextField in one go instead of separately.
The book doesn't explain anything about it, just "now use that". I can properly make JPanels and JTextFields, but this is new to me. I did some Google searches and I saw I was indeed doing it wrong, but what I learned from searching doesn't seem to be right either. I completely don't know how to work with the mentioned, and through Google searches I found it works just like JTextField(String TextFieldText, int columns) but 2 Strings + 1 int isn't accepted. Help would be very much appreciated. Below I've written the code of displaying 1 JTextField with a pre-existing message (the window stuff's in another class), which I suppose would help you with how to respond (as I know there are multiple ways to code stuff, so I suppose it's most useful if you know what I know and add to that)
The code of what I know for displaying a textfield (and yes, I know I can use the word 'test' in more occassions, but I chose not to. Oh, and because I need a JPanel, I've already added 'extends JPanel'. And it seems the forum messes with the tabs which are of course in):
package testTest;
import javax.swing.*;
public class TestPanel extends JPanel
{
private JTextField test;
public TestPanel()
{
test2 = new JTextField("test", 5);
add(test2);
}
}Last edited by Someone001; 10-24-2011 at 10:47 PM.
- 10-24-2011, 02:20 PM #2
Re: Public JTextField question
I'm not sure what you mean by "I need to make a JPanel + JTextField in one go instead of separately". You have to create them one at a time. The closest you can get is to use an Object that creates both, but you already seem to be doing that.
By the way, using the code tags will preserve your code formatting.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-24-2011, 10:47 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Re: Public JTextField question
Well, with the mentioned "Public JTextField variable (String JPanelText, String TextFieldText, int columns)" (forgot to mention "variable"), apparantly I should be able to make a JPanel AND a JTextField, which is what I mean with "in one go".
- 10-25-2011, 01:39 PM #4
Re: Public JTextField question
I'm still really not sure what you mean. Are you talking about the JPanelText variable? That's just a variable name, it could be anything, and it doesn't mean you can create a JPanel along with a JTextField.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-26-2011, 01:27 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 3
- Rep Power
- 0
Re: Public JTextField question
Well, the question's simply: how do I use it? Because just copying + pasting it (with actual Strings and an int) like that in my Java code, or making a regular JTextField with a second String, doesn't do anything. I completely don't know how to use it.
- 10-26-2011, 02:45 PM #6
Re: Public JTextField question
If I understand that question correctly, I believe the answer is you just have to add your text field to a JPanel, which is in a JFrame.
Recommended reading: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
public jTextField ?
By vagf in forum AWT / SwingReplies: 3Last Post: 06-07-2011, 10:56 AM -
JTextfield question
By xyknight in forum New To JavaReplies: 3Last Post: 04-08-2011, 04:25 PM -
JTextField Question
By Rocketz in forum New To JavaReplies: 1Last Post: 03-09-2011, 12:38 AM -
JTextField Question
By Kyle227 in forum New To JavaReplies: 5Last Post: 05-09-2010, 07:44 AM -
JTextField question
By Chasingxsuns in forum New To JavaReplies: 5Last Post: 07-14-2009, 02:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks