[英]How can I change the whole look of a JTextField
嘗試在 JTextField 上設置自定義邊框或覆蓋paintBorder
正如您所說,您可以覆蓋paintComponent()。 這是簡單 JPanel 中 JTextField 的片段:
JPanel panel = new JPanel();
JTextField textField = new JTextField() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLUE);
g.drawLine(10, getHeight() - 10, getWidth() - 10, getHeight() - 10);
}
};
panel.add(textField);
textField.setPreferredSize(new Dimension(100, 50));
textField.setForeground(Color.BLUE);
textField.setHorizontalAlignment(JTextField.CENTER);
add(panel);
setSize(200, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.