Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 958324

me-kell
Unregistered




Not all Borders in BorderFactory are Flyweights
      07/31/03 09:43 AM

Actually only RaisedBevelBorder, LoweredBorder and EtchedBorder use shared instances and thus are implemented as flyweights. For all the other Borders (in JDK1.3.1: LineBorder, TitledBorder, EmptyBorder, CompoundBorder, and MatteBorder) the BorderFactory returns a new instance!

You can test it with the following or better take a look at the sources under "BorderFactory.java"
Border b1, b2;
b1 = BorderFactory.createCompoundBorder();
b2 = BorderFactory.createCompoundBorder();
System.out.println( "CompoundBorder="+ ((b1 == b2) ? "flyweight" : "no"));
b1 = BorderFactory.createEmptyBorder();
b2 = BorderFactory.createEmptyBorder();
System.out.println( "EmptyBorder="+ ((b1 == b2) ? "flyweight" : "no"));
b1 = BorderFactory.createEtchedBorder();
b2 = BorderFactory.createEtchedBorder();
System.out.println( "EtchedBorder="+ ((b1 == b2) ? "flyweight" : "no"));
b1 = BorderFactory.createLineBorder(Color.blue);
b2 = BorderFactory.createLineBorder(Color.blue);
System.out.println( "LineBorder="+ ((b1 == b2) ? "flyweight" : "no"));
b1 = BorderFactory.createLoweredBevelBorder();
b2 = BorderFactory.createLoweredBevelBorder();
System.out.println( "LoweredBevelBorder="+ ((b1 == b2) ? "flyweight" : "no"));
b1 = BorderFactory.createRaisedBevelBorder();
b2 = BorderFactory.createRaisedBevelBorder();
System.out.println( "RaisedBevelBorder="+ ((b1 == b2) ? "flyweight" : "no"));
b1 = BorderFactory.createMatteBorder(1, 1, 1, 1, Color.blue);
b2 = BorderFactory.createMatteBorder(1, 1, 1, 1, Color.blue);
System.out.println( "MatteBorder="+ ((b1 == b2) ? "flyweight" : "no"));
b1 = BorderFactory.createTitledBorder("");
b2 = BorderFactory.createTitledBorder("");
System.out.println( "TitledBorder="+ ((b1 == b2) ? "flyweight" : "no"));

which outputs the following:

CompoundBorder=no
EmptyBorder=flyweight
EtchedBorder=flyweight
LineBorder=no
LoweredBevelBorder=flyweight
RaisedBevelBorder=flyweight
MatteBorder=no
TitledBorder=no

Post Extras Print Post   Remind Me!     Notify Moderator


Entire topic
Subject Posted by Posted on
* Not all Borders in BorderFactory are Flyweights me-kell 07/31/03 09:43 AM

Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Thread views: 8210

Rate this thread

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5