0
How to make a text field in java ?
How to make a text field like a text box my palette is not working in Netbeans!! I am trying to figure it out since days . No result
12 Answers
+ 1
There are plenty of text areas but the most simple one is the swing JTextArea
+ 1
Here's an example for a simple window with Textfield:
import javax.swing.*;
 
public class JTextFieldExample {
    public static void main(String[] args) {
        JFrame mainFrame = new JFrame();
        mainFrame.setTitle("JTextField Example");
        mainFrame.setSize(300, 150);
        JPanel panel = new JPanel();
 
        JLabel label = new JLabel("Yout Name");
        panel.add(label);
 
        // Create Textfield
        // Text and Columncount set directly
        JTextField tfName = new JTextField("PUT TEXT HERE", 15);
        // add textfield to panel
        panel.add(tfName);
 
        JButton buttonOK = new JButton("OK");
        panel.add(buttonOK);
 
        mainFrame.add(panel);
        mainFrame.setVisible(true);
 
    }
}
+ 1
@Maksym Eclipse for the win
+ 1
I have to agree that eclipse is dead, and Intelij is better but I just hate the UI of intelij or visual, I have to feel comfortable in the IDE and I'm not in both of them
+ 1
Yes, I don't like it too. I would definitly switch if there was a eclipse theme
+ 1
Well thanks, I'll going to try it
0
JTextField myField = new JTextField(); This is swing text field
But you must to connect it to some container like JFrame or JPanel like this //myPanel.add(myField);
All of the components must have parameters set like:
JFrame myFrame = new JFrame;
myFrame.setSize(800,600);
myFrame.setLocationRelativeTo(null);
myFrame.setVisible(true);
and later
JPanel myPanel = new JPanel();
myPanel.setSize(200,50);
myPanel.setLocation(1,1);
myPanel.setVisible(true);
and last but important, add it to frame
myFrame.add(myPanel);
myFrame.repaint();
0
Ah, and stop using NetBeans. IntelliJ is muuuch better
0
Eclipse is dead. Maybe still for C++ if someone can't afford Visual or is on Linux but for sure not for Java. 
0
Did you tried Darcula theme from IntelliJ? I am using it daily also changed font to inconsolata. 
OP sorry for irrelevant spam. 
0
There is a plugin that changes syntax coloring to eclipse theme, but if it comes to buttons or menu bar, well, nope. Yet most big corporations are on IntelliJ now for its efficiency. 
0
Thank you all!  It really is helpful to me! 



