【发布时间】:2014-02-21 03:31:04
【问题描述】:
好的,所以我需要一点帮助,我正在使用一组变量来声明我的字体等,我通过使用 derivedFont 方法使粗体和斜体函数工作 - 创建新字体并应用新字体风格等
这个比较棘手,因为我从文本框中获取值并将其应用于 fontSize 变量,然后将其应用于我那里的 currentFont...
帮助?! :(
我的代码的 sn-p 如下...
public class Practice01 extends javax.swing.JFrame {
private int fontStyle;
private int fontSize = 12;
private void changeSize(){
Font currentFont = edtText.getFont(); //getting the current font
fontSize = Integer.parseInt(txtSize.getText()); //getting the number input from the text box and putting it to the fontSize variable
txtSize.setText(Integer.toString(fontSize)); //setting the txtSize entry to the fontSize variable?
currentFont.deriveFont(fontSize); //deriving a new font
edtText.setFont(currentFont.deriveFont(fontSize)); //setting the new font and size to the text box.
}
这是我的字体变量位...
Font serifFont;
Font monoFont;
Font sansserifFont;
public Practice01() {
serifFont = new Font ("Serif", fontStyle, fontSize);
monoFont = new Font ("Monospaced", fontStyle, fontSize);
sansserifFont = new Font ("SansSerif", fontStyle, fontSize);
initComponents();
}
【问题讨论】:
标签: java swing text fonts textbox