摆动:显示悬停在另一个面板上的透明面板

时间:2011-01-03 10:24:23

标签: java swing jlayeredpane

我想显示一个textArea显示一些文本(将显示日志行),并在其上方有一个动画gif。我尝试了here描述的解决方案,但我得到的只是灰色屏幕。提示?

public class TestLayeredPanes {

    private JFrame frame = new JFrame();
    private JLayeredPane lpane = new JLayeredPane();

    public TestLayeredPanes() {
        frame.setPreferredSize(new Dimension(600, 400));
        frame.setLayout(new BorderLayout());
        frame.add(lpane, BorderLayout.CENTER);

        //Build the animated icon
        JLabel buildingIcon = new JLabel();
        buildingIcon.setIcon(new ImageIcon(this.getClass().getResource(
                "/com/ct/tasks/cmviewer/gui/progress_bar.gif")));       
        JPanel iconPanel = new JPanel();
        iconPanel.add(buildingIcon);

        //Build the textArea
        JTextArea textLog = new JTextArea("Say something");     
        JPanel textPanel = new JPanel();
        textPanel.add(new JScrollPane(textLog));

        //Add the panels to the layered pane
        lpane.add(textPanel, 0);
        lpane.add(iconPanel, 1);

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new TestLayeredPanes();
    }

}

3 个答案:

答案 0 :(得分:1)

尝试将动画GIF放在根窗格的玻璃窗格上:

http://download.oracle.com/javase/tutorial/uiswing/components/rootpane.html

答案 1 :(得分:1)

JXLayer更容易做到这一点。查看JXLayer个样本。

您还可以查看XSwingX

的代码

答案 2 :(得分:1)

既然你开始使用一个工作示例,为什么要从你复制的例子中删除代码行?

分层窗格不使用布局管理器,因此组件的大小为(0,0),因此无需显示任何内容。示例中的setBounds(...)方法是有原因的。

相关问题