0

Java form loads with gif background playing however any images and text that overlay it appear for a few seconds only to disappear forever. The form was built using the Netbeans form builder within a null layout with the gif as a JLabel at the bottom and numerous text and images over it.

The gif is rather large roughly 350mb

 BPanel = new javax.swing.JPanel();
        Board = new javax.swing.JLabel();
BPanel.setPreferredSize(new java.awt.Dimension(1156, 786));
        Board.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/Game_2.gif"))); // NOI18N
        Board.setToolTipText("");
        Board.setAlignmentY(0.0F);

        javax.swing.GroupLayout BPanelLayout = new javax.swing.GroupLayout(BPanel);
        BPanel.setLayout(BPanelLayout);
        BPanelLayout.setHorizontalGroup(
            BPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(BPanelLayout.createSequentialGroup()
                .addComponent(Board)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        BPanelLayout.setVerticalGroup(
            BPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Board, javax.swing.GroupLayout.DEFAULT_SIZE, 910, Short.MAX_VALUE)
        );

        getContentPane().add(BPanel);
        BPanel.setBounds(0, 0, 1600, 910);

        setSize(new java.awt.Dimension(1616, 944));
        setLocationRelativeTo(null);
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Brad
  • 11
  • 1
  • 1
    It "looks" like you've added al the components to the same container. Instead, add them to the component acting as the background component – MadProgrammer Jul 08 '15 at 22:34
  • 2
    1) Don't use null layout for this. 2) How are you displaying your image? 3) Best if you draw it within the paintComponent method of the JPanel that holds all components. Any search of this site will tell you the same. Either that or make the JLabel the background container, but be careful with its preferredsize and its layout. 4) Learn and use Java naming conventions so that we can better understand your code. 5) Avoid using NetBeans code generation. – Hovercraft Full Of Eels Jul 08 '15 at 22:35
  • For [example](http://stackoverflow.com/questions/21957612/setting-loaded-gif-as-a-background/21960539#21960539) and [example](http://stackoverflow.com/questions/13886476/more-than-one-jpanel-in-a-frame-having-a-brackground-image-and-another-layer-w/13886648#13886648) – MadProgrammer Jul 08 '15 at 22:37
  • Oh, and I'd avoid `GroupLayout`, it's not really "developer" friendly and is meant for UI designers. It makes it REALLY hard to make changes to the UI by hand – MadProgrammer Jul 08 '15 at 22:41
  • Or limit its use to [small doses](http://stackoverflow.com/a/8504753/230513). – trashgod Jul 09 '15 at 01:49
  • Thanks! It works perfectly now – Brad Jul 09 '15 at 07:01

0 Answers0