问题描述
我想实现。根据不同的细节,你可能要重用的典范。通常很容易只写比的图,并在同一时间的模型的图。但是,必须平衡与现有模型的适合性的观点的需要。
That means I'd consider a new swing UI component. Here's how to write custom painting for one. Depending on the details, you may want to reuse a model. Generally it is easier to only write a view than a view and a model at the same time; however, you must balance the needs of the view with the suitability of the existing model.
如果您选择一个现有的模型,Document接口是什么,你应该code你对视图。你可以把你的领导从JTextPane的或JTextArea中的视图组件,depeding上,如果你想添加样式,以文本的能力。
If you choose an existing model, the Document interface is what you should code your view against. You can take your lead from the JTextPane or JTextArea view components, depeding on if you want the ability to "add style" to your text.
不要忘记,观点实际上没有做画在一个结构良好的Swing组件。如果那样的话,就不会是能够被剥皮(跟随平台的主题)。这意味着,当你将提供一个Swing视图(通常像JPagedBook一个名称模式),这一观点将必须连接到UIDelegate由它来完成视图的实际绘制。这允许每个视图多个UIDelegates,用含有如何呈现(平局)的说明,其方式认为是与平台的外观和感觉一致的每个UIDelegate
Don't forget that the view actually doesn't do the painting in a well structured Swing component. If it did, then it would not be able to be skinned (to follow the platform's theme). This means that while you will provide a Swing view (typically with a name pattern like JPagedBook), that view will have to be coupled to a UIDelegate which does the actual drawing of the view. This allows multiple UIDelegates for each view, with each UIDelegate containing the instructions of how to render (draw) the view in a manner that is consistent with the look-and-feel of the platform.
解决这个问题的最大的问题通常是额外的工作涉及到正确支持的外观和感觉,缺乏适当的UIDelegate注册知识(所以当视图绘制,它发现的东西,将画它)。这是值得额外的几个小时(或几天的夫妇,如果GUI组件编程是有点新的给你),使它象秋千其余工作。最终你就会有不一样的感觉图书馆的独立的部分组件。
The biggest issues around this is typically the extra work involved to properly support look-and-feel, and the lack of knowledge of proper UIDelegate registration (so when the view draws, it finds something that will draw it). It's worth the extra few hours (or couple of days if GUI component programming is sort of new to you) to make it work like the rest of Swing. In the end you'll have a component that doesn't feel like a "separate" part of the library.
这篇关于在的Java Swing / AWT的页转到效应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!