CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Adding background image to jTextArea?

  1. #1
    Join Date
    Jul 2005
    Posts
    3

    Adding background image to jTextArea?

    I'd like to add a bacground image to JTextArea. Haw can I do that?

  2. #2
    Join Date
    Jun 2005
    Location
    Ukraine
    Posts
    45

    Re: Adding background image to jTextArea?

    Code:
    public final class AreaTest extends JFrame
    {
        public AreaTest(final Image image)
        {
            Container container = getContentPane();
            container.setLayout(new BorderLayout());
    
            JTextArea textArea = new JTextArea()
            {
                //Image grayImage = GrayFilter.createDisabledImage(image);
                {setOpaque(false);}
    
                public void paintComponent (Graphics g)
                {
                    g.drawImage(image, 0, 0, (int)getSize().getWidth(), (int)getSize().getHeight(), this);
                    //g.drawImage(grayImage, 0, 0, (int)getSize().getWidth(), (int)getSize().getHeight(), this);
                    super.paintComponent(g);
                }
            };
    
            container.add(textArea);
        }
    
    
        public static void main(String[] args)
        {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Image image = toolkit.createImage("bg.jpg");
    
            AreaTest areaTest = new AreaTest(image);
            areaTest.setSize(300, 300);
            //areaTest.setResizable(false);
            areaTest.setTitle("Area test");
            areaTest.setVisible(true);
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)