我有个问题.它看起来HTMLEditorKit只是忽略空格.有我的示例代码:
public class TestEditor extends JFrame {
public TestEditor(){
createConnection();
createGUI();
}
private void createGUI(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
JScrollPane scroll1=new JScrollPane(text);
JScrollPane scroll2=new JScrollPane(html);
JSplitPane split=new JSplitPane();
split.setLeftComponent(scroll1);
split.setRightComponent(scroll2);
split.setDividerLocation(0.5);
split.setResizeWeight(0.5);
getContentPane().add(split);
setTitle("Test");
setPreferredSize(new Dimension(600,300));
pack();
}
private void createConnection(){
text=new JTextPane();
html=new JTextPane();
html.setContentType("text/html");
html.getStyledDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
update();
}
@Override
public void removeUpdate(DocumentEvent e) {
update();
}
@Override
public void changedUpdate(DocumentEvent e) {
update();
}
private void update(){
if(fromText) return;
fromHtml=true;
text.setText(html.getText());
fromHtml=false; …Run Code Online (Sandbox Code Playgroud) 我想知道是否有任何方法可以在xaml中使用元素中的PathFigure资源PathGeometry.假设我有一个ResourceDictionary,其中有两个PathFigure对象,'x:Key'属性分别等于"Figure1"和"Figure2".我的目标是创建一个PathGeometry带有Figures包含图1和图2的集合的属性.我可以使用代码隐藏文件轻松地完成它,但是我想知道有没有办法只使用xaml.
<PathFigure IsClosed="True" StartPoint="2,9" x:Key="Figure1">
<ArcSegment Point="15,9" Size="6.5, 2"/>
<LineSegment Point="15,12"/>
<ArcSegment Point="2,12" Size="6.5, 2"/>
</PathFigure>
<PathFigure IsClosed="True" StartPoint="10,7" x:Key="Figure2">
<LineSegment Point="10, 2"/>
<LineSegment Point="13,2"/>
<LineSegment Point="13,7"/>
<ArcSegment Point="10,7" Size="2,2" IsLargeArc="True"/>
</PathFigure>
Run Code Online (Sandbox Code Playgroud)
我现在可以创建一个PathGeometry:
<PathGeometry FillRule="Nonzero" x:Key="1">
<PathFigureCollection>
//Here I want to put Figure1 and Figure2
</PathFigureCollection>
</PathGeometry>
Run Code Online (Sandbox Code Playgroud)
我想我可以写一些MarkupExtension来做以下事情,但我正在寻找最好的方法.谢谢你的建议.