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

28th Jan 2017, 1:28 PM
Yadumeet Singh
Yadumeet Singh - avatar
12 Answers
+ 1
There are plenty of text areas but the most simple one is the swing JTextArea
28th Jan 2017, 1:30 PM
Daniel S
Daniel S - avatar
+ 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); } }
28th Jan 2017, 1:48 PM
R4xx4r
R4xx4r - avatar
+ 1
@Maksym Eclipse for the win
28th Jan 2017, 1:51 PM
Daniel S
Daniel S - avatar
+ 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
28th Jan 2017, 1:59 PM
Daniel S
Daniel S - avatar
+ 1
Yes, I don't like it too. I would definitly switch if there was a eclipse theme
28th Jan 2017, 2:02 PM
Daniel S
Daniel S - avatar
+ 1
Well thanks, I'll going to try it
28th Jan 2017, 2:07 PM
Daniel S
Daniel S - avatar
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();
28th Jan 2017, 1:50 PM
Maksym ZieliƄski
Maksym ZieliƄski - avatar
0
Ah, and stop using NetBeans. IntelliJ is muuuch better
28th Jan 2017, 1:50 PM
Maksym ZieliƄski
Maksym ZieliƄski - avatar
0
Eclipse is dead. Maybe still for C++ if someone can't afford Visual or is on Linux but for sure not for Java.
28th Jan 2017, 1:53 PM
Maksym ZieliƄski
Maksym ZieliƄski - avatar
0
Did you tried Darcula theme from IntelliJ? I am using it daily also changed font to inconsolata. OP sorry for irrelevant spam.
28th Jan 2017, 2:02 PM
Maksym ZieliƄski
Maksym ZieliƄski - avatar
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.
28th Jan 2017, 2:07 PM
Maksym ZieliƄski
Maksym ZieliƄski - avatar
0
Thank you all! It really is helpful to me!
2nd Feb 2017, 1:37 AM
Yadumeet Singh
Yadumeet Singh - avatar