Question

I have a problem that the JFrame is not showing upmy components. When i opened the GasStationPanel in WindowBuilder it show well, but the MainFrame is show as a blank windows. Please, I need you help here. Thanks!

The JFrame code is:

public class MainFrame extends JFrame {
    private GasStationPanel pnlMainGasStation;

    public MainFrame() throws SecurityException, IOException {
        try {               UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception e) {
            e.printStackTrace();
        }

        getContentPane().setLayout(new BorderLayout());
        this.pnlMainGasStation = new GasStationPanel("all cars","pumps","coffee");
        this.add(pnlMainGasStation, BorderLayout.CENTER);
        setLocationRelativeTo(null);

        setTitle("GasStation");
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Utils.closeApplication(MainFrame.this);
            }
        }); 

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = new Dimension();
        frameSize.setSize(screenSize.width*0.7, screenSize.height*0.9);
        setSize(frameSize);
        setVisible(true);    
    }
    public GasStationPanel getMainPanel() {
        return pnlMainGasStation;
    }
}

The GasStationPanel Code:

public class GasStationPanel extends JPanel {
private JSplitPane splinterRight, splinterLeft;
private AllCarsPanel allCarsPanel;
private FuelPumpListPanel fuelPumpsListPanel;
private CoffeeHousePanel coffeeHousePanel;

private List<GasStationController> allListeners;

public AllCarsPanel getAllCarsPanel() {
    return allCarsPanel;
}

public FuelPumpListPanel getFuelPumpsListPanel() {
    return fuelPumpsListPanel;
}

public CoffeeHousePanel getCoffeeHousePanel() {
    return coffeeHousePanel;
}

public GasStationPanel(String allCarsStr, String fuelPumpsListStr,
        String coffeeHousePanelStr) throws SecurityException, IOException {
    // Init Listeners List
    this.allListeners = new ArrayList<GasStationController>();
    // Layout and size
    setLayout(new BorderLayout());

    // Build panels
    allCarsPanel = new AllCarsPanel();
    fuelPumpsListPanel = new FuelPumpListPanel();
    coffeeHousePanel = new CoffeeHousePanel();

    // Split the screen to three
    splinterRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splinterLeft = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splinterLeft.setLeftComponent(allCarsPanel);
    splinterLeft.setRightComponent(fuelPumpsListPanel);
    splinterRight.setLeftComponent(splinterLeft);
    splinterRight.setRightComponent(coffeeHousePanel);
}

public void registerListener(GasStationController gasStationController) {
    this.allListeners.add(gasStationController);
}
Was it helpful?

Solution

In short, you never add any components to your container. For example, in your GasStationPanel code, perhaps you should try invoking add(Component) by passing in your JSplitPanes as an argument. For example:

add(splinterLeft, BorderLayout.CENTER);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top