[英]JTextfield Fonts and Attributes problem
So I am creating a program that changes the JTextField depending on what the user Chooses. 因此,我正在创建一个程序,该程序根据用户选择的内容更改JTextField。 So its pretty much like a Word Document with fonts(from a JComboBox), sizes, and attributes(Bold...etc).
因此,它非常像带有字体(来自JComboBox),大小和属性(粗体...等)的Word文档。 Obviously mine is very small and only works with a single line(A JTextField).
显然我的很小,只能用一行(一个JTextField)工作。 The Problem i'm getting is that After I've written some things down into the field with specific attributes and I want to add more words down with different attributes, it changes the whole text field rather than just the new part I added.
我遇到的问题是,在将一些东西写到具有特定属性的字段中之后,我想添加更多具有不同属性的单词,这会更改整个文本字段,而不仅仅是我添加的新部分。 I know the problem with it is
我知道它的问题是
Writer.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if((e.getKeyChar() >= e.VK_A && e.getKeyChar()<= e.VK_Z) || (e.getKeyChar() >= 'a' && e.getKeyChar()<='z')|| e.getKeyChar() == '\b' ) // Checks to make sure No Numbers
{
Writer.setEditable(true);
}
else
{
Writer.setEditable(false);
}
if(font.equals("Arial"))
{
if(size.equals("8"))
{
setSize = 8;
}
else if(size.equals("10"))
{
setSize = 10;
}
else if(size.equals("12"))
{
setSize = 12;
}
if(color.equals("Black"))
{
setColor = Color.BLACK;
}
else if(color.equals("Blue"))
{
setColor = Color.BLUE;
}
else if(color.equals("Red"))
{
setColor = Color.red;
}
Font font = new Font("Arial", setAttribute, setSize);
Writer.setFont(font); // I Know that this sets the font everytime, so i'm pretty sure this is where my problem is.
Writer.setForeground(setColor);
}
Any ideas on how I can make the Change so it newly entered characters can have different fonts than the previous characters. 关于如何进行更改以使其新输入的字符的任何想法都可以具有与以前的字符不同的字体。
用于样式化文本的 JComponents-如何使用编辑器窗格和文本窗格 , 此处的示例, 此处 ,此论坛的一些示例
JTextFields allow the use of HTML. JTextFields允许使用HTML。 It might take a bit of work to parse and insert new html code, but you might be able to do it that way.
解析和插入新的html代码可能需要一些工作,但是您可以采用这种方式。
There's a list of WYSIWYG text editors for Java here . 这里有Java的WYSIWYG文本编辑器列表。 I especially like metaphase editor , based on Charles Bell's
HTMLDocumentEditor
. 我特别喜欢基于Charles Bell的
HTMLDocumentEditor
中期编辑器 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.