Questo è il codice relativo alla classe che rappresenta il pannello
public class MyPanel extends JPanel
{
private Image backgroundImage = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/icons/background.png"));
public MyPanel()
{
super();
setOpaque(false);
}
@Override
public void paint(Graphics g)
{
BufferedImage img = null;
try {
setBackground(new Color(0,0,0,0));
img = ImageIO.read(getClass().getResource("/icons/background_compress.png"));
MediaTracker track = new MediaTracker(this);
track.addImage(img, 0);
track.waitForID(0);
} catch (IOException | InterruptedException ex) {
System.out.println("Errore : "+ex.getMessage());
}
g.drawImage(img, 0, 0, null);
super.paintComponents(g);
this.repaint();
}
}
Questo è il codice dei componenti:
private void init_textPane()
{
textPane = new JTextPane();
textPane.setEditable(false);
textPane.setHighlighter(null);
textPane.setBackground(new Color(0,0,0,0));
textPane.setAutoscrolls(true);
DefaultCaret caret = (DefaultCaret) textPane.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
textPane.setEditorKit(new WrapEditorKit());
textPane.setCaret(caret);
scrollLog = new JScrollPane(textPane);
scrollLog.setSize(new Dimension(790,525));
scrollLog.setLocation(new Point(5,3));
scrollLog.getVerticalScrollBar().setUI(new MyScrollBarUI());
scrollLog.getHorizontalScrollBar().setUI(new MyScrollBarUI());
scrollLog.getVerticalScrollBar().setAutoscrolls(true);
scrollLog.setBorder(new MyLineBorder2(Color.black, 1, true));
scrollLog.setBackground(new Color(0,0,0,0));
scrollLog.setVisible(true);
}
Il tutto poi con
protected void setPanels()
{
panel = new MyPanel();
panel.setLayout(null);
panel.add(scrollLog);
panel.setVisible(false);
}