我怎么能在java中使用不同的字体类型和大小相同的文本区域 [英] how can i use different font types and sizes for the same text area in java

查看:286
本文介绍了我怎么能在java中使用不同的字体类型和大小相同的文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在我的Java形式的文本区域。如何使用不同的字体类型和大小
$ b $ pre $ code public double roundTwoDecimals(double d){
DecimalFormat twoDForm = new DecimalFormat ( ###。);
return Double.valueOf(twoDForm.format(d));
}
int ches = 0;
ref = Integer.parseInt(jTextField6.getText());
nam = jTextField7.getText();
add = jTextArea3.getText();
ph = jTextField8.getText();

bill(jTextArea4);

total();

double tt = 0;
if(flag == 1){
uclist(nam);
ches = jComboBox2.getSelectedIndex();
} else if(flag == 0){
iclist(nam,add,ph);
ches = not();


(int i = 0; i if(qty [i]!= 0){
t [ i] = amt [i] / 1.135;
tv [i] = amt [i] - t [i];
isalest((i + 1),ches,qty [i],price [i]);
uSale(nItem [i],qty [i]);
ustock((i + 1),qty [i]);
jTextArea4.append(\\\
+ nItem [i] ++ qty [i] +
+ price [i] ++ r(t [i])) ;
}
tt + = tv [i];


jTextArea4.append(\\\
\tTotal(including vat @ 13.5%+ r(tt)); // TODO在这里添加你的处理代码:$ b $或许更好地使用另一个可以处理更复杂的格式的文本组件作为JTextPane而不是JTextArea,因为后者更多的是用于显示简单的文本。

但是,如果要以表格形式显示数据,考虑使用具有等宽字体(例如Font.MONOSPACED)的JTextArea,并使用String.format(...)格式化文本,或者甚至更好地使用JTable来代替JTextArea。



在附注中,考虑重命名所有的变量,以使它们的名称具有逻辑意义。我们很难使用名为r()或者一个名为t []的数组,这包括你的GUI变量,看起来你正在使用NetBeans来生成你的GUI(这是一个非常有用的东西)她的建议,其他时间),这个IDE将很容易让你重命名你的GUI变量,这也是我强烈建议的。几个星期后,当你查看这个代码时,如果你将jTextField7重命名为clientLastNameField或者其他类型的话,这将更有意义。


i have a text area in my java form. how can i use different font types and sizes

 public double roundTwoDecimals(double d) {
    DecimalFormat twoDForm = new DecimalFormat("#.##");
    return Double.valueOf(twoDForm.format(d));
}
    int ches = 0;
    ref = Integer.parseInt(jTextField6.getText());
    nam = jTextField7.getText();
    add = jTextArea3.getText();
    ph = jTextField8.getText();

    bill(jTextArea4);

    total();

    double tt = 0;
    if (flag == 1) {
        uclist(nam);
        ches = jComboBox2.getSelectedIndex();
    } else if (flag == 0) {
        iclist(nam, add, ph);
        ches = not();
    }

    for (int i = 0; i < no(); i++) {
        if (qty[i] != 0) {
            t[i] = amt[i] / 1.135;
            tv[i] = amt[i] - t[i];
            isalest((i + 1), ches, qty[i], price[i]);
            uSale(nItem[i], qty[i]);
            ustock((i + 1), qty[i]);
            jTextArea4.append("\n" + nItem[i] + "  " + qty[i] + "  "
                    + price[i] + "  " + r(t[i]));
        }
        tt += tv[i];
    }

    jTextArea4.append("\n\tTotal(including vat @13.5%" + r(tt));// TODO add your handling code here:

解决方案

Better perhaps to use another text component that can handle more complex formatting such as a JTextPane rather than a JTextArea since the latter is more for the display of simple text only.

But having said that, if you want to display data in table form, consider using a JTextArea that has a monospaced font such as Font.MONOSPACED and using String.format(...) to format the text, or even better, use a JTable in place of the JTextArea.

On a side note, consider renaming all of your variables so that their names make logical sense. It's hard for us to make heads or tails out of a method named r() or an array named t[]. This includes your GUI variables. It appears that you're using NetBeans to generate your GUI (and that's the subject of another recommendation for some other time), and this IDE will easily let you rename your GUI variables, and again this is something I strongly recommend. A few weeks from now when you review this code, it will make much more sense if you rename jTextField7 to clientLastNameField or some-such.

这篇关于我怎么能在java中使用不同的字体类型和大小相同的文本区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆