楼主 admin 发表于2014-6-20 17:54:00
奇新Java电子表格控件支持上标和下标,可以显示h2o,m3,m2等这些化学符号和立方米,平方米单位

代码:

            DataGridModel model = getDataGrid().getDataGridModel();           
            SimpleAttributeSet superscript = new SimpleAttributeSet();
            StyleConstants.setSuperscript(superscript, true);
            StyleConstants.setForeground(superscript, Color.RED);
            SimpleAttributeSet subscript = new SimpleAttributeSet();
            StyleConstants.setSubscript(subscript, true);
            StyleConstants.setForeground(subscript, Color.GREEN);
            String example = "test superscript and subscript: h2o, m3, m2";
            StyledText text = new StyledText(example);
            text.setCharacterAttributes(example.length() -10 , 1, subscript, false);
            text.setCharacterAttributes(example.length() - 5 , 1, superscript, false);
            text.setCharacterAttributes(example.length() - 1 , 1, superscript, false);
            model.setValueAt(text, 2, 2);