1 回答
TA貢獻1895條經(jīng)驗 獲得超7個贊
他們說一張圖片描繪了一千個單詞,所以這里有一個 6K 單詞的答案。

請注意,在 Nimbus & Motif PLAF 中,不可編輯文本字段的背景看起來與可編輯文本字段相同,而在其他三個中,它看起來不同。
禁用的文本字段與所有 PLAF 中的可編輯或不可編輯字段不同。
代碼
使用此代碼在您的系統(tǒng)/JRE 上進行測試。
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.border.*;
import javax.imageio.ImageIO;
import java.io.*;
public class TextFieldPLAF {
TextFieldPLAF() {
initUI();
}
public final void initUI() {
UIManager.LookAndFeelInfo[] lafInfos = UIManager.getInstalledLookAndFeels();
try {
for (UIManager.LookAndFeelInfo lAFI : lafInfos) {
saveImageOfLookAndFeel(lAFI);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void saveImageOfLookAndFeel(UIManager.LookAndFeelInfo lafi) throws IOException {
String classname = lafi.getClassName();
try {
UIManager.setLookAndFeel(classname);
} catch (Exception ex) {
ex.printStackTrace();
}
JComponent ui = new JPanel(new GridLayout(1, 0));
ui.setBorder(new TitledBorder(classname));
int cols = 13;
JTextField tf;
tf = new JTextField("Editable & Enabled", cols);
ui.add(tf);
tf = new JTextField("Not Editable", cols);
tf.setEditable(false);
ui.add(tf);
tf = new JTextField("Not Enabled", cols);
tf.setEnabled(false);
ui.add(tf);
JOptionPane.showMessageDialog(null, ui);
BufferedImage bi = new BufferedImage(
ui.getWidth(), ui.getHeight(), BufferedImage.TYPE_INT_RGB);
ui.paint(bi.getGraphics());
File dir = new File(System.getProperty("user.home"));
File f = new File(dir, String.format("PLAF-%1s.png", classname));
ImageIO.write(bi, "png", f);
}
public static void main(String[] args) {
Runnable r = () -> {
new TextFieldPLAF();
};
SwingUtilities.invokeLater(r);
}
}
添加回答
舉報
