When I give in for example a String called : This.is.a.test and press the convert button , the textfield becomes empty.
I used String function : replace all to replace the dots with spaces.
When I set the text of the textfield with a normal string(" ") it works but with a variable it doesnt work.
Thanks in advance
Heres my code :
import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JButton; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class TestReplace { private JFrame frame; private JTextField inputString; String s; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { TestReplace window = new TestReplace(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public TestReplace() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); inputString = new JTextField(); inputString.setBounds(67, 88, 307, 34); frame.getContentPane().add(inputString); inputString.setColumns(10); JLabel lblGeefStringIn = new JLabel("String :"); lblGeefStringIn.setBounds(173, 55, 108, 14); frame.getContentPane().add(lblGeefStringIn); JButton btnNewButton = new JButton("Convert"); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { s = inputString.getText(); s = s.replaceAll(".", " "); inputString.setText(s); } }); btnNewButton.setBounds(162, 150, 108, 23); frame.getContentPane().add(btnNewButton); } }