import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;public class FA_AboutBox extends JDialog implements ActionListener { int red = 102; int green = 102; int blue = 102; AboutPanel pan_about; String [][] inhalt; public FA_AboutBox(JFrame parent, String[][] inhalt){ super(parent, "Programm-Info", true); this.inhalt = inhalt; setDefaultCloseOperation(DISPOSE_ON_CLOSE); Container contPane = getContentPane(); contPane.setLayout(new GridBagLayout()); JLayeredPane layPane = new JLayeredPane(); layPane.setBorder(BorderFactory.createLoweredBevelBorder()); layPane.setPreferredSize(new Dimension(400,400)); GridBagConstraints gbc = new GridBagConstraints(); // Hintergrundbild laden Image hintergrund = getToolkit().getImage("images/InfoBackgr.jpg"); MediaTracker mt = new MediaTracker(this); int imgBreite = 400; int imgHoehe = 400; Image hintergrOpt = hintergrund.getScaledInstance(imgBreite, imgHoehe, Image.SCALE_FAST); mt.addImage(hintergrund, 0); mt.addImage(hintergrOpt, 0); try { // Warten, bis das Image vollständig geladen ist, mt.waitForAll(); } catch (InterruptedException e) { System.out.println(e); } JLabel label = new JLabel(new ImageIcon(hintergrOpt)); label.setBounds(0,0,400,400); layPane.add(label, new Integer(0)); pan_about = new AboutPanel(new Dimension(imgBreite, imgHoehe)); JScrollPane scr_pane = new JScrollPane(pan_about); scr_pane.setPreferredSize(new Dimension(300,300)); scr_pane.setBounds(50,50,300,300); scr_pane.setOpaque(false); layPane.add(scr_pane, new Integer(1)); gbc.gridy = 0; gbc.insets = new Insets(6,6,6,6); contPane.add(layPane, gbc); // OK-Button hinzufügen JButton but_ok = new JButton(" ok "); gbc.gridy = 1; contPane.add(but_ok, gbc); but_ok.addActionListener(this); but_ok.addKeyListener(new FA_KeyListener(this)); //setResizable(false); pack(); // Fenster zentrieren Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); int xpos = (screenSize.width - getWidth()) / 2; int ypos = (screenSize.height - getHeight()) / 2; setLocation(xpos, ypos); // Textfareb wird in Schleife langsam aufgebaut (new Thread() { public void run(){ while (blue > 0 || red < 255) { if (blue > 0){ blue--; } if (red < 255){ red++; } if (green < 255){ green++; } pan_about.repaint(); try{ Thread.sleep(5); } catch(InterruptedException ie) { System.out.println(ie.getMessage()); } } } }).start(); setVisible(true); } public void actionPerformed(ActionEvent e){ fensterSchliessen(); } public void fensterSchliessen() { setVisible(false); dispose(); System.exit(0); } private class AboutPanel extends JPanel { private Font font1 = new Font("SansSerif", Font.BOLD,16); private Font font2 = new Font("SansSerif", Font.BOLD,22); public AboutPanel (Dimension dim) { setPreferredSize(dim); setMinimumSize(dim); setMaximumSize(dim); } public void paint(Graphics g){ Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(red,green,blue)); for (int i = 0; i<inhalt.length; i++) { for (int j = 0; j<2; j++) { g2d.setFont(font2); g2d.drawString("Test JScrollPane", 110,50); g2d.setFont(font1); g2d.drawString(inhalt[i][j], j*100+30, i*40+100); } } } } public static void main(String args[]) { String [][] inhalt = { {"Zeile 1", "mit festem Hintergrund"}, {"Zeile 2", "Text 2"}, {"Zeile 3", "Text 3 abcdefghij"}, }; new FA_AboutBox(new JFrame(), inhalt);}}