Revision: 40825
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 8, 2011 16:11 by lethalwire
Initial Code
import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; public class CustomTextArea extends JPanel { private static final long serialVersionUID = 7502204181430286959L; private static final Image image = new ImageIcon( "images/windows.jpg" ).getImage(); public static void main(String[] args) { JFrame frame = new JFrame( "Hello" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); JPanel panel = new JPanel(); panel.add( new CustomTextArea() ); frame.setContentPane( panel ); frame.pack(); frame.setVisible( true ); } public CustomTextArea() { super(); init(); } public Dimension getPreferredSize() { return new Dimension( image.getWidth( null ), image.getHeight( null ) ); } public void init() { JTextArea ta = new JTextArea(); Font f = new Font("Verdana", Font.BOLD, 36 ); ta.setFont( f ); ta.setLineWrap( true ); ta.setWrapStyleWord( true ); ta.setPreferredSize(getPreferredSize()); ta.setOpaque( false ); add( ta ); } public void paintComponent( Graphics g ) { super.paintComponent( g ); g.drawImage(image, 0, 0, null); } }
Initial URL
Initial Description
This is a sample JTextArea with a custom background image.
Initial Title
Custom JTextArea with Background Image
Initial Tags
image, background
Initial Language
Java