Question

I have chartPanel (JFreeChart), buttonPanel and errorPanel.

    frame.add(chartPanel, BorderLayout.PAGE_START);
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    errorPanel = new JLabel("Error String");
    errorPanel.setHorizontalAlignment(JLabel.CENTER);
    frame.getContentPane().add(buttonPanel, BorderLayout.CENTER);
    frame.getContentPane().add(errorPanel, BorderLayout.SOUTH);

When I change height of application window, buttonPanel and errorPanel disappeared.

When I don't use JLabel:

    frame.add(chartPanel);
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);

it's okey in changing of height of application window. How to make it right and not have problems with window zoom?

enter image description here

Was it helpful?

Solution

When you add to the JFrame the default location is CENTER but since you add to the chart to the PAGE_START now its not scalable...

solution:

take it out and just say

frame.add(chartPanel);

and for the errorPanel and ButtonPanel

just make a new JPanel with BorderLayout and add it to the SOUTH of your Frame Layout. Then inside that JPanel add your ButtonPanel and ErroPanel just like what you did in your Jframe..

OTHER TIPS

Try this:

frame.addComponentListener(new ComponentListener(){

    public void componentResized(ComponentEvent e) {
        frame.pack();
    }

    public void componentMoved(ComponentEvent e) {}
    public void componentShown(ComponentEvent e) {}
    public void componentHidden(ComponentEvent e) {}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top