English 中文(简体)
滚动卡卡彩票
原标题:Swing CardLayout

What is the default behavior of cardlayout when you add two cards with same identifier. For example, if have panel1 which is added. Later in the program, I add panel2 with the same string identifier. Is the default behavior to replace panel1 with panel2 in the card stack? Thanks

问题回答

下面是 CardLayount s 执行 adddadLayount Concomonent () , 由 addLayount Concomonent( compent, 对象限制) 执行。

public void addLayoutComponent(String name, Component comp) {
    synchronized (comp.getTreeLock()) {
        if (!vector.isEmpty()) {
            comp.setVisible(false);
        }
        for (int i=0; i < vector.size(); i++) {
            if (((Card)vector.get(i)).name.equals(name)) {
                ((Card)vector.get(i)).comp = comp;
                return;
            }
        }
        vector.add(new Card(name, comp));
    }
}

CardLayount 维持着一个 Card 对象的矢量(见下文)。看起来,在探测到名称碰撞时,用新添加的 component 替换了 Card 中具有相同名称的 Component 中的 。因此,有特定名称的 show () 将显示该名称中添加的 last 组件。

class Card implements Serializable {
    static final long serialVersionUID = 6640330810709497518L;
    public String name;
    public Component comp;
    public Card(String cardName, Component cardComponent) {
        name = cardName;
        comp = cardComponent;
    }
}

能够 添加相同标识符的多卡。 您只能 [编辑] < engene% em> 。 您只能 still [/ 编辑] 导航到 show( container, String) 显示面板添加的 [编辑] 首先 < /strike{ strick_ engenem> last [/editit] 。

卡斯佩尔





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...