0

If a GUI application has a JFrame containing a JPanel with an image inside its entire body (so that the image is a kinda background image), and I want to add a (transparent) JTabbedPane on the JPanel.

Now I am using the GUI Builder of NetBeans to place a panel on the picture, but it probably goes under the picture. How can I being it on the top (that is above the picture, so that the tabbed pane is visible).

PS: I am trying to do it with GUI Builder, since I am completely new to Java Swing. So please tell me a way in GUI Builder preferably, if there is any?


Edit1:- package 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);
    }

}
Solace
  • 8,612
  • 22
  • 95
  • 183
  • Not an answer, but if you are at the learning Swing stage, consider avoiding use of code-generation utilities and instead learn to code by hand as this will get you "closer to the metal" enabling you to learn more and quicker. Later when you're more facile with Swing, then sure, use a Code generator, since at this stage you'll have the knowledge needed to use this to create more than just basic GUI's. – Hovercraft Full Of Eels Apr 27 '14 at 18:43
  • @HovercraftFullOfEels Actually I was not inclined to learn Swing (and I would like to give a lot of time to learning it before doing something like this) but now I have this task. I have to make it somehow and then after finishing it I will be in a position to make time to learn it. Actually I started it thinking that everything will be just drag and drop in NetBeans, and in the middle of it, I know that I need to actually learn it, and that is not possible without finishing it. Yes that is the real situation. – Solace Apr 27 '14 at 18:53
  • I commiserate with you and your predicament, but understand that while drag and drop GUI builders are great for creating simplistic applications, the moment you try to veer away from the standard, the much more difficult they become, and in fact doing this -- trying to alter your GUI so that it is not a most basic type of program, will require significant knowledge in Swing, knowledge gained through doing hand coding. That's about all I can say on the subject since I'm not a NetBeans expert and cannot answer your question on how to solve this within the NetBeans environment. Best of luck! – Hovercraft Full Of Eels Apr 27 '14 at 19:15
  • Sounds like you're using a JLabel to display the image. Try adding the JTabbedPane to the JLabel. If your not using a JLabel, then you probably overriding paint of the JPanel, painting the image there, which is painting over the content, in this case, use paintComponent method instead – MadProgrammer Apr 27 '14 at 20:20
  • @MadProgrammer Actually I have done this (that too not without a spoonfeeding [here](http://stackoverflow.com/questions/23322564/how-to-make-the-image-scale-its-size-automatically-according-to-the-parent-jlabe)), then added this panel to the parent frame. Now I need to add tabbedpane on this picture, but when I try to place it there on the picture, it rather goes under the picture. Can you suggest anything about it? – Solace Apr 27 '14 at 20:31
  • How is the image rendered? Either it's done using a JLabel or cpustom painting – MadProgrammer Apr 27 '14 at 20:33
  • I think it is custom painting. You can check the answer and the comments in the link I have just added to my comment. Thank you for responding – Solace Apr 27 '14 at 20:34
  • @Zarah If you look at the code I helped you with yesterday, and use the `paintComponent` method of the panel to which the tabbed pane is added for painting the image instead of the solid background, you'll get what you want. – user1803551 Apr 28 '14 at 23:46
  • @user1803551 Can you chat if you are free, I will like to take a few suggestions? – Solace Apr 28 '14 at 23:51
  • I guess so, http://chat.stackoverflow.com/rooms/51632/swing-help if anyone wants to join. – user1803551 Apr 28 '14 at 23:58

0 Answers0