如何让光标从JTextField的左上角开始?当我使用.setPreferredSize()调整高度时,文本保持居中。这是字段和按钮的代码。
public class GUIWindow extends JFrame{
private JTextField inputBox = new JTextField(20);
private JTextField outputBox = new JTextField(20);
private JButton encodeButton = new JButton("Encode");
private JButton decodeButton = new JButton("Decode");
public GUIWindow(){
JPanel mainPanel = new JPanel(new FlowLayout());
outputBox.setPreferredSize(new Dimension(80, 80));
inputBox.setPreferredSize(new Dimension(80, 80));
outputBox.setEditable(false);
mainPanel.add(inputBox);
mainPanel.add(encodeButton);
mainPanel.add(decodeButton);
mainPanel.add(outputBox);
Container container = getContentPane();
container.add(mainPanel);
}
}