Hallo,
ich versuche hier ein Bild als Hintergrund zu setzen. Allerdings wird beim Aufruf der Klasse das Bild mal richtig angezeigt, mal wird es verpixelt dargestellt. Woran könnte das liegen?
mal so:
so ists richtig:
hier mein Code:
ich versuche hier ein Bild als Hintergrund zu setzen. Allerdings wird beim Aufruf der Klasse das Bild mal richtig angezeigt, mal wird es verpixelt dargestellt. Woran könnte das liegen?
mal so:
so ists richtig:
hier mein Code:
Java:
public class DlgDefaultMenu extends JDialog{
private static final long serialVersionUID = 1L;
private Image _bgImage=null;
private class ContentPane extends JPanel{
private static final long serialVersionUID = 1L;
public ContentPane(){
setLayout(new BorderLayout());
}
public void paintComponent(Graphics g){
super.paintComponent(g);
if (_bgImage!=null)
g.drawImage(_bgImage, 0, 0, this.getWidth(), this.getHeight(), Color.BLACK, this);
}
}
public DlgDefaultMenu(Window owner, JButton[] buttons){
super(owner, Dialog.ModalityType.DOCUMENT_MODAL);
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setSize(860,400);
setUndecorated(true);
setLayout(new BorderLayout());
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation( (d.width - getSize().width) /2, (d.height - getSize().height )/2 );
_bgImage=Toolkit.getDefaultToolkit().getImage(getClass().getResource("/img/Blokus_logo_3.png"));
setContentPane(new ContentPane());
JPanel _pnlGlobalButtons=new JPanel();
_pnlGlobalButtons.setLayout(new FlowLayout());
_pnlGlobalButtons.setBackground(Color.BLACK);
createGlobalButtonPanel(_pnlGlobalButtons, buttons);
getContentPane().add(_pnlGlobalButtons, BorderLayout.SOUTH);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public void createGlobalButtonPanel(JPanel globalpanel, JButton[] globalbuttons){
InputStream is= this.getClass().getResourceAsStream("/fonts/m04.TTF");
Font ttfBase = new Font("Monospaced", Font.BOLD, 12);
try {
ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);
} catch (FontFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Font ttfReal=ttfBase.deriveFont(Font.PLAIN, 9);
for(JButton x:globalbuttons){
x.setFont(ttfReal);
x.setBackground(Color.BLACK);
x.setForeground(Color.WHITE);
globalpanel.add(x);
}
}
}