问题
[UPDATE] i fixed the problem. user "Hovercraft Full Of Eels" was right, i changed 3D graphics settings prefer to nvidea driver and problem fixed
i have problem and can't understand what is matter. i am creating simple GUI window and putting JTextField object on it. when i run project and enter text in text field it does not displays properly.
i already tryed to reinstal java, but can't fix problem.
can anyone help me?
here is my GUI window image

here is my code (no exception thrown, nor error was occured!)
package test;
import javax.swing.*;
import java.awt.*;
public class MainClass {
public static void main(String[] args) {
new Form().Run();
}
}
class Form{
JFrame form = new JFrame();
JButton btn = new JButton();
JTextField txt = new JTextField();
public Form(){
form.setLayout(new FlowLayout());
form.setSize(500, 500);
form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btn.setText("caption");
form.add(btn);
txt.setColumns(10);
form.add(txt);
}
public void Run(){
form.setVisible(true);
}
}
回答1:
Try to change your "Look and Feel" settings in your GUI-Class, there should be the string "Nimbus". Change it to "Windows" and try it again. The second thing you can try is to set a Border to your JTextfield, probably it works.
The code for changing or to set a Border on your JTextfield:
JTextField your_field = new JTextField(10);
your_field.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, Color.black));
来源:https://stackoverflow.com/questions/25823367/java-text-in-textfield-messing-up