0

私は MiGLayout を使用しており、フリークです。レイアウトの単一のインスタンスを作成し、それをすべてのパネルに使用することが可能かどうかを考えていました。ちょっと興味があるんだけど...

4

2 に答える 2

2

これは、レイアウト マネージャーがレイアウトに関連するデータを保持しているかどうかに完全に依存します。一般に、制約を受け取るレイアウト マネージャーはそれらを格納する必要があるため、コンテナーと 1 対 1 でインスタンス化する必要があります。

特に MigLayout を参照して、複数のコンテナーに適用できないデータの量を確認してください。

public final class MigLayout implements LayoutManager2, Externalizable
{
    // ******** Instance part ********

    /** The component to string constraints mappings.
     */
    private final Map<Component, Object> scrConstrMap = new IdentityHashMap<Component, Object>(8);

    /** Hold the serializable text representation of the constraints.
     */
    private Object layoutConstraints = "", colConstraints = "", rowConstraints = "";    // Should never be null!

    // ******** Transient part ********

    private transient ContainerWrapper cacheParentW = null;

    private transient final Map<ComponentWrapper, CC> ccMap = new HashMap<ComponentWrapper, CC>(8);
    private transient javax.swing.Timer debugTimer = null;

    private transient LC lc = null;
    private transient AC colSpecs = null, rowSpecs = null;
    private transient Grid grid = null;
    private transient int lastModCount = PlatformDefaults.getModCount();
    private transient int lastHash = -1;
    private transient Dimension lastInvalidSize = null;

    private transient ArrayList<LayoutCallback> callbackList = null;

    private transient boolean dirty = true;
于 2010-03-19T18:07:45.167 に答える
0

一部のレイアウト マネージャーは、1 つだけで動作しますContainer( などBoxLayout)。私の推測では、同じレイアウト マネージャーを再利用しようとしても得られるメリットはほとんどありません。

于 2010-03-19T23:54:05.040 に答える