0
    public static JTextArea area = new JTextArea()
{
    public void createObject()
    {
        setLineWrap(true);
        setSize(850, 1100);
        setOpaque(true);
        setBackground(Color.WHITE);
        setBounds(0, 0, 850, 1100);
        setBorder(BorderFactory.createLineBorder(Color.lightGray, 1));
        setBorder(new EmptyBorder(new Insets(100, 100, 100, 100)));
        setFont(new Font("TimesRoman", Font.PLAIN, 11)); 
    }
};

public static JPanel panelImg = new JPanel()
{
    public void paintComponent(Graphics g)
    {
        try{
            add(area);
            Image img = new ImageIcon(ImageIO.read(new File("C:\\Program Files (x86)\\Oasis Script Writer\\Textures\\Backgrounds\\Background.jpg"))).getImage();
            Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
            setPreferredSize(size);
            setMinimumSize(size);
            setMaximumSize(size);
            setSize(size);
            setLayout(null);
            g.drawImage(img, 0, 0, null);
        } catch (Exception backgroundError) {
            System.out.println("ERROR: " + backgroundError);
        }
    }
};

My goal is to overlay a jtextarea over a jpanel containing a full screen image so that I can place the jtextarea inside of a jscrollpane without effecting the jpanel and the image which it contains. Thank you in advance.

After that I added the jpanel to the jframe intending that the jtextarea was added to the jpanel and overlapping the image background.

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.getContentPane().add(panelImg);

heres a diagram: https://drive.google.com/file/d/0B9e6NVTCbgdwTFNkRlFDUkNYVXM/view?usp=sharing

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
ryanpvw
  • 39
  • 1
  • 1
  • 6
  • Something like [this](http://stackoverflow.com/questions/14329310/jtextarea-not-selectable-but-still-showing-a-ghost-cursor/14329538#14329538) or [this](http://stackoverflow.com/questions/14177340/remove-jtextpanes-white-background-without-setopaque-over-a-translucent-jfram/14179477#14179477) or [this](http://stackoverflow.com/questions/12737266/custom-java-swing-textcomponent-from-scratch/12737418#12737418) or [this](http://stackoverflow.com/questions/13560065/how-to-write-text-over-image-inside-rectangular-region-displayed-in-jpanel/13561675#13561675) – MadProgrammer Oct 05 '15 at 05:57
  • or [this](http://stackoverflow.com/questions/14761598/write-text-into-a-jtextpane-with-an-image-background/14763273#14763273) or [this](http://stackoverflow.com/questions/15992831/inserting-an-image-under-a-jtextarea/15993627#15993627) – MadProgrammer Oct 05 '15 at 06:00
  • http://stackoverflow.com/questions/8792075/overlay-panel-above-another – Viraj Nalawade Oct 05 '15 at 06:00
  • 1
    Don't call `add(area)` within the `paintComponent` method; in fact, don't modify the state of the UI at from within the `paintComponent`, simply paint the image. Add your components are per usual to the `panelImg` and let the layout manager to deal with it – MadProgrammer Oct 05 '15 at 06:03

0 Answers0