B
Beni
Gast
Also dieser Thread ist irgendwie komisch...
Aber eigentlich benötigt man da nicht viel Code:
Aber eigentlich benötigt man da nicht viel Code:
Code:
package forum;
import java.awt.*;
import javax.swing.*;
public class Beispiel{
public static void main( String[] args ) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
// Ein JLabel als Hintergrund verwenden
JLabel background = new JLabel( createIcon() );
frame.setContentPane( background );
// Componenten auf den Hintergrund setzen
background.setLayout( new GridBagLayout() );
JPanel panel = new JPanel( new GridLayout( 3, 1, 10, 10 ));
panel.add( new JButton( "A" ));
panel.add( new JButton( "B" ));
panel.add( new JButton( "C" ));
panel.setOpaque( false );
background.add( panel, new GridBagConstraints( 0, 0, 1, 1, 1.0, 1.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets( 5, 5, 5, 5 ), 0, 0 ));
// das ganze Anzeigen
frame.setSize( 500, 500 );
frame.setVisible( true );
}
// Ein Icon herstellen, es ist egal, woher das Icon kommt
public static Icon createIcon(){
return new Icon(){
public int getIconHeight() {
return 500;
}
public int getIconWidth() {
return 500;
}
public void paintIcon( Component c, Graphics g, int x, int y ) {
Graphics2D g2 = (Graphics2D)g;
g2.setPaint( new GradientPaint( x, y, Color.RED, x+getIconWidth(), y+getIconHeight(), Color.GREEN ));
g2.fillRect( x, y, getIconWidth(), getIconHeight() );
}
};
}
}