tło w oknie

0

Hej :)

Jak ustawic tlo oknienka w postaci obrazka np. jpg???
0

Przykład z http://www.jguru.com

import javax.swing.*;
import java.awt.*;

public class BackgroundSample {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Background Example");
    final ImageIcon imageIcon = new ImageIcon("draft.gif");
    JTextArea textArea = new JTextArea() {
      Image image = imageIcon.getImage();
      Image grayImage = GrayFilter.createDisabledImage(image);
      {setOpaque(false);}  // instance initializer
      public void paintComponent (Graphics g) {
        g.drawImage(grayImage, 0, 0, this);
        super.paintComponent(g);
      }
    };
    JScrollPane scrollPane = new JScrollPane(textArea);
    Container content = frame.getContentPane();
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(3);
    frame.setSize(250, 250);
    frame.setVisible(true);
  }
}

Innymi słowy musisz nadpisać metodę paintComponent dla Frame'a pamiętając o setOpaque(false);

1 użytkowników online, w tym zalogowanych: 0, gości: 1