1

I want to show a textArea showing some text (will show log lines) , and have an animated gif hoovering above it. I tried the solution described here , but all I get is a grey screen. Hints?

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();
    }

}
Community
  • 1
  • 1
Yossale
  • 14,165
  • 22
  • 82
  • 109

3 Answers3

1

Try putting your animated GIF on the glass pane of your root pane:

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

Thomas
  • 17,016
  • 4
  • 46
  • 70
1

JXLayer make easier to do that. Look at JXLayer samples.

You also can take a look at code of XSwingX

lujop
  • 13,504
  • 9
  • 62
  • 95
1

Since you started with a working example, why did you remove lines of code from the example you copied?

Layered panes don't use a layout manager therefore the size of your components are (0, 0), so there is nothing to display. The setBounds(...) method in the example are there for a reason.

camickr
  • 321,443
  • 19
  • 166
  • 288