質問

I have read the docs, but the docs seem vague to me and I'm having a hard time understanding what it is exactly and what it's used for.

Two question regarding this:

  1. What exactly is the AttributeSet interface? What is the purpose of instances of classes implementing this interface?

  2. Also, the Style interface is a subinterface of the AttributeSet interface. What exactly is this interface? What is the purpose of instances of classes implementing it?

役に立ちましたか?

解決

An AttributeSet implementation is supposed to hold a set of Key,Value pair objects.

You can use HashMap/HashTable etc for you own implementation of AttributeSet.

AttributeSet doesnt have any method for adding key values. There comes MutableAttributeSet

Style 

is a MutableAttributeSet which provides Listener support. Which means you can change the key-value based on some changeListener.

他のヒント

Can you give me an example of using Style or MutableAttributeSet in practice? For example when creating a word processor?

Start with the section from the Swing tutorial on General Text Component features. It contains a working example that allows you to play with attributes like font, color, italic, bold...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top