Guten Mittag,
ich habe ein mit dem BorderLayout bei JFrame ich versuche ein JPanel rechts an ein JFrame anzubinden. Doch wenn ich frame.add(JPanel, LINE_END) mach funktioniert es nicht und es bindet sich oben links.
[Java]
public void neueFlaeche(String name, int height, int width, String position)
{
/*if(position.equals("Mitte")*/ShowCanvas Flaeche = new ShowCanvas(height, width);
ImageContainer background = new ImageContainer();
background.loadImage("images/sunw02.jpg");
//Flaeche.setBackgroundImage(background);
add(Flaeche, BorderLayout.PAGE_START);
repaint();
}
[/Java]
[Java]
class ShowCanvas extends JPanel
{
ImageContainer background;
int width, height;
ShowCanvas(int nwidth, int nheight) {
super(new BorderLayout());
setBackground(Color.black);
width = nwidth;
height = nheight;
setSize(width, height);
//addMouseMotionListener(new MouseMotionHandler());
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
if(background!=null)
g2D.drawImage(background.getBufferedImage(),0,0, this);
}
class MouseMotionHandler extends MouseMotionAdapter {
public void mouseDragged(MouseEvent e) {
/*x = e.getX();
y = e.getY();
repaint();*/
}
public void mouseMoved(MouseEvent e) {
}
}
public void setBackgroundImage (ImageContainer back)
{
background = back;
background.rescaleImage(width, height);
repaint();
}
}
[/Java]
Ich hoffe Ihr findet die Lösung
Schonmal danke im voraus
ich habe ein mit dem BorderLayout bei JFrame ich versuche ein JPanel rechts an ein JFrame anzubinden. Doch wenn ich frame.add(JPanel, LINE_END) mach funktioniert es nicht und es bindet sich oben links.
[Java]
public void neueFlaeche(String name, int height, int width, String position)
{
/*if(position.equals("Mitte")*/ShowCanvas Flaeche = new ShowCanvas(height, width);
ImageContainer background = new ImageContainer();
background.loadImage("images/sunw02.jpg");
//Flaeche.setBackgroundImage(background);
add(Flaeche, BorderLayout.PAGE_START);
repaint();
}
[/Java]
[Java]
class ShowCanvas extends JPanel
{
ImageContainer background;
int width, height;
ShowCanvas(int nwidth, int nheight) {
super(new BorderLayout());
setBackground(Color.black);
width = nwidth;
height = nheight;
setSize(width, height);
//addMouseMotionListener(new MouseMotionHandler());
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
if(background!=null)
g2D.drawImage(background.getBufferedImage(),0,0, this);
}
class MouseMotionHandler extends MouseMotionAdapter {
public void mouseDragged(MouseEvent e) {
/*x = e.getX();
y = e.getY();
repaint();*/
}
public void mouseMoved(MouseEvent e) {
}
}
public void setBackgroundImage (ImageContainer back)
{
background = back;
background.rescaleImage(width, height);
repaint();
}
}
[/Java]
Ich hoffe Ihr findet die Lösung
Schonmal danke im voraus