Results 1 to 6 of 6
  1. #1
    Someone001 is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default 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.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default 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!

  3. #3
    Someone001 is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default 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".

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default 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!

  5. #5
    Someone001 is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Default 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.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,985
    Rep Power
    9

    Default 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

  1. public jTextField ?
    By vagf in forum AWT / Swing
    Replies: 3
    Last Post: 06-07-2011, 10:56 AM
  2. JTextfield question
    By xyknight in forum New To Java
    Replies: 3
    Last Post: 04-08-2011, 04:25 PM
  3. JTextField Question
    By Rocketz in forum New To Java
    Replies: 1
    Last Post: 03-09-2011, 12:38 AM
  4. JTextField Question
    By Kyle227 in forum New To Java
    Replies: 5
    Last Post: 05-09-2010, 07:44 AM
  5. JTextField question
    By Chasingxsuns in forum New To Java
    Replies: 5
    Last Post: 07-14-2009, 02:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •