'Problems with JButton for two days - Won't display correct, video of issue down below

My buttons ain't showing as they should.

  • If I add to my JPanel it is stuck in one location and I can't change it's location (x,y)
  • If I add to my JFrame it is a fullscreen button

Video to show my issue https://www.youtube.com/watch?v=Y5IBMGP9kh0

https://github.com/Drafter47/Draft4Anything/tree/main/Pandemic/src

I can't wrap my head around where I am making a big mistake...

class Main

class Main {

    public static void main(String[] args) {
        GameUI game = new GameUI();
        game.gameStart();
    }
}

class GameUI

import javax.swing.*;
import java.awt.*;

public class GameUI extends JPanel{

    private JFrame mainFrame;
    private MyFrame bg;
    private JButton sanfrancisco;

    public void gameStart() {
        gameGUI();
    }

    //Userinterface
    private void gameGUI() {
        JButton but1 = new JButton("SAN FRANCISCO");
        but1.setBounds(500, 200, 200, 200); //set parameters for the button's size
        JButton but2 = new JButton("SAN ");
        but2.setBounds(500, 500, 100, 100); //set parameters for the button's size

        //Set graphics for background and fields
        bg = new MyFrame();

        //Game window
        mainFrame = new JFrame("Pandemic - by KMJ"); //make main frame (window)
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //close application when window is closed
        mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); //full screen mode
        mainFrame.setVisible(true); //show the window
        mainFrame.add(bg);
//      mainFrame.add(but1);

        //TOP BAR for cards, score etc.
        JPanel topPanel = new JPanel();
        topPanel.setBackground(Color.black);
        topPanel.setPreferredSize(new Dimension(100, 100));
        mainFrame.add(topPanel, BorderLayout.NORTH);
//      topPanel.add(but2);

        //BOTTOM BAR for actions
        JPanel bottomPanel = new JPanel();
        bottomPanel.setBackground(Color.black);
        bottomPanel.setPreferredSize(new Dimension(100, 100));
        mainFrame.add(bottomPanel, BorderLayout.SOUTH);

        //RIGHT BAR for player's cards
        JPanel rightPanel = new JPanel();
        rightPanel.setBackground(Color.blue);
        rightPanel.setPreferredSize(new Dimension(130, 130));
        mainFrame.add(rightPanel, BorderLayout.EAST);

        //LEFT BAR for rules
        JPanel leftPanel = new JPanel();
        leftPanel.setBackground(Color.blue);
        leftPanel.setPreferredSize(new Dimension(130, 130));
        mainFrame.add(leftPanel, BorderLayout.WEST);

        //ADD BUTTONS
        mainFrame.add(sanfrancisco);
    }
}

class MyFrame

import javax.swing.*;
import java.awt.*;

public class MyFrame extends JPanel {
    public MyFrame() {
        Timer timer = new Timer(0, event -> { //set a delay for printing
            repaint();
        }); //Anonymoous class
        timer.start();
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent();
        Image img = new ImageIcon("src\\images\\pandemicmap.jpg");
        Graphics2D g2d = (Graphics2D) g;

        g2d.drawImage(img, 0, 0, null);
    }
}


Solution 1:[1]

Finally, I could spot the problem. Here is my solution. I think the obvious way to figure out what was going wrong was after enabling the redirection logs -

error_log /var/log/nginx/error.log notice;
 rewrite_log on;

Here is the location context.

location /api/v1 {

            # uncomment the below two lines to see the redirection.
            # the re-direction happens from  /api/v1/ to /
            # error_log /var/log/nginx/error.log notice;
            # rewrite_log on;
            rewrite ^(/api/v1)(.*)/$ https://$host$2 break;
            
        }

        location / {
            uwsgi_pass unix:///tmp/sb_web_wsgi.sock;
            include uwsgi_params;
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sjoshi