0

What I want to do is a put my component close to the right side of my application. Second option is to put it in specified x,y coordinates. However I tried setBounds() setLocation() and add(component, BorderLayout.LINE_END) funcions. Nothing works for me. What is wrong is with my code?

public class MapaSwiata extends JPanel implements ActionListener {

    private BufferedImage mapa;
    private File imageFile;

    public MapaSwiata(){
        super();

        imageFile = new File("C:\\Users\\Katie\\Documents\\Eclipse\\Samolot\\src\\Pics\\img_mapa.jpg");

        try {
            mapa = ImageIO.read(imageFile);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        JOutlookBar outlookBar = new JOutlookBar();

        outlookBar.addBar( "Pogoda", getDummyPanel("One"));
        outlookBar.addBar( "Informacje o locie", getDummyPanel("Two" ));
        outlookBar.addBar( "Rozkład Lotow", getDummyPanel( "Three" ) );
        outlookBar.setVisibleBar( 2 );

        add(outlookBar, BorderLayout.LINE_END); 
    }

    public static JPanel getDummyPanel( String name )
    {
        JPanel panel = new JPanel( new BorderLayout() );
        panel.add( new JLabel( name, JLabel.CENTER ) );
        return panel;
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.drawImage(mapa, 0, 0, getWidth()-300, getHeight()-150, null);
    }
}

I also tried to put in a JButton or something else. Everything always appears in the top center of the application. Sorry for polish names of variables.

Thanks in advance

Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106

1 Answers1

1

If you want that BorderLayout.LINE_END has an effect, you have to apply the BorderLayout to the Container. To do that, simply add

setLayout(new BorderLayout());

to your constructor MapaSwiata().

NOTE: Your child panels don't require the BorderLayout.

Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106