0

如果一个 GUI 应用程序有一个JFrame包含一个JPanelimage其整个主体内的一个(这样图像是一个有点背景图像),并且我想JTabbedPaneJPanel.

现在我正在使用NetBeans的GUI Builder在图片上放置一个面板,但它可能位于图片下方。我怎样才能将它放在顶部(即在图片上方,以便选项卡式窗格可见)。

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

}
4

0 回答 0