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);
}
}
};
我的目标是将jtextarea覆盖在包含全屏图像的jpanel上,这样我就可以将jtextarea放在jscrollpane中,而不会影响jpanel及其包含的图像。提前谢谢。
之后我将jpanel添加到jframe,意图将jtextarea添加到jpanel并重叠图像背景。
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.getContentPane().add(panelImg);
见图:https://drive.google.com/file/d/0B9e6NVTCbgdwTFNkRlFDUkNYVXM/view?usp=sharing