当我尝试将它放在图像顶部时,我的标签窗格会在图像下方?

时间:2014-04-27 18:13:31

标签: java image swing netbeans gui-builder

如果GUI应用程序的JFrame包含JPanel,其整个正文中包含image(以便图像是有点背景图像),我想添加一个JTabbedPane上的(透明)JPanel

现在我正在使用 NetBeans GUI Builder 在图片上放置一个面板,但它可能会在图片下面。 < strong>如何将其置于顶部(位于图片上方,以便可以看到选项卡式窗格)。

PS:我正在尝试使用GUI Builder,因为我对Java Swing完全不熟悉。所以请在GUI Builder中告诉我一个最好的方法,如果有的话?


EDIT1: -     包com.dev_nna.dbp;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class PanelForm extends javax.swing.JPanel {

    private BufferedImage image;

    public PanelForm() {
        try {
            image = ImageIO.read(getClass().getResource("/com/dev_nna/dbp/scheduler/resources/abstract-blue-white-background.jpg"));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>                        

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(1000, 1000);
    }

}

0 个答案:

没有答案