jtextfield

Java Check If Two JTextField Has The Same Content [duplicate]

隐身守侯 提交于 2019-12-12 06:39:10
问题 This question already has answers here : How do I compare strings in Java? (23 answers) Closed 6 years ago . I have two JTextFields txf1 and txf2. In both of them I input the same content (for example: "test"). I made and If statement: if (txf1.getText() == txf2.getText()) { System.out.println("Equal"); } else { System.out.println("Error"); } Why it prints out the error message? I even made a System.out.println(txf1.getText()) and System.out.println(txf2.getText()) and the same looks equal,

Java Swing - How to get the value of text in a TextField from another class

痴心易碎 提交于 2019-12-12 06:18:46
问题 Okay, beginner Java coder here. I'm trying to make a multi-purpose math utility application with Java Swing. One of the things I want it to do is be able to solve basic logarithms. I have the logic all down, but I'm having trouble with the outputting itself. I have a class (named "LogTab") and within it is a nested static class (named "LogPanel") for the actual input area. The button is outside the LogPanel class, and when I press it I want it to be able to take the values of the TextFields

Resizing JTextField in JMenuBar

时间秒杀一切 提交于 2019-12-12 05:37:13
问题 I'm trying to add a JTextField as a search bar to a JMenuBar at the top of my JFrame . My problem is that the JTextField keeps getting resized to take up all available space in the JMenuBar , and I don't want it to. I've tried setPreferredSize() and setMaximum Size() , but these didnt work, presumably because the LayoutManager used in the JMenuBar doesn't respect these sizes. I also tried adding the JTextField to a JPanel with a FlowLayout and adding the panel to the JMenuBar , but I get

Validate JTextField

ぐ巨炮叔叔 提交于 2019-12-12 05:24:12
问题 How do I validate JTextField for a personal number? For example, I would like it to validate something formatted like 841017-4567 . 回答1: Read up on JFormattedTextField and MaskFormatter. JFormattedTextField phoneField = new JFormattedTextField(new MaskFormatter("######-####")); 来源: https://stackoverflow.com/questions/4926745/validate-jtextfield

Transparency for JTextField not working

蓝咒 提交于 2019-12-12 05:21:41
问题 I'm working on a log in server & my JTextFields aren't transparent when I set Opaque to false . My code: //username JTextField jUsername = new JTextField(10); jUsername.setBounds(520, 284, 190, 25); jUsername.setOpaque(false); jUsername.setBorder(null); getContentPane().add(jUsername); //password JTextField jPassword = new JTextField(15); jPassword.setBounds(520, 374, 190, 25); jPassword.setOpaque(false); jPassword.setBorder(null); //jPassword.setBackground(new Color(Color.TRANSLUCENT));

Way to save jList data into a txt file?

前提是你 提交于 2019-12-12 05:00:32
问题 I am looking for a way to save the users input from a jlist into a txt file. It's for a homework project. I have the program set up to take user input from a textfield, then it goes into the jlist once they hit the add button. The jlist has a defaultlistmodel on it, and I'm wondering if there is a way to create a save button and allow it to save the complete jlist into a .txt file. Also, here is my code: import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame;

Add and remove button dynamically in Swing frame

血红的双手。 提交于 2019-12-12 04:54:09
问题 I'm developing a swing application. In that I've a JFrame which add JTextfield and JButton dynamically on the button click.and remove the created components if the user clicks the same button. In the below screen image , when user clicks ADD button new row was added, and text was changed to REMOVE like in 2nd image. New Row added and previous button text changed to REMOVE. Now, if I click the REMOVE button, then the newly added row has to dispose and then button has to change the text again

Cannot change input language in jTextField

醉酒当歌 提交于 2019-12-12 04:54:00
问题 Why can't I switch input language in jtextfield and JOptionPane.showInputDialog() ? On my computer I can, but on other computer I can write only system locale language symbols. Ctrl + Shift or Ctrl + Alt + Shift is not working in application, but it is working when app is not focus Locale.setDefault(Locale.ENGLISH); //tried it System.setProperty("user.language", "en"); // and it private void showPasswordWindow() { String pass = JOptionPane.showInputDialog(null, "Enter password", "Secure",

remove last character from jtextfield

心已入冬 提交于 2019-12-12 04:49:14
问题 I want to a JTextField to have maximum characters, Ive been trying out this code, what im trying to do is, if a user enters more then 13 characters it should erase the last character entered, I also tried with the Unicode Character (by replacing the \b to \u0008) but it gives the same result, this is my code: if(EditTxtFName.getText().length() > 10) { EditTxtFName.setBackground(Color.red); EditTxtFName.setText(EditTxtFName.getText() + "\b"); } else { EditTxtFName.setBackground(Color.white); }

Swing: taking variables from two private jTextField?ActionPerformed classes

可紊 提交于 2019-12-12 04:46:30
问题 I'm in NetBeans 8.2 and I've constructed a nice jFrame GUI for a Binary-to-Decimal converter, I think I have the code in my two text fields correct but I can't figure out how to access the variables for my Button to perform operations on. I have 3 method operations called parseBinary, isBinary, and illegal that I want to use to perform operations on my two text fields. In NetBeans when you code a button the method is locked to private so that's my issue. I will post all my of code and