Vra

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 dit nuttig?

Oplossing

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..

Ander wenke

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) {}
});
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top