How to expand the window by clicking a button?

Asked

Viewed 21 times

0

I’m trying to expand the screen size using Java Swing. When I click a button I need to increase the height of the screen, consequently appearing two more buttons.

I tried to do this in the method below, but it doesn’t work:

    private static int ALTURA_INICIAL_TELA_VISIVEL = 320;
    private static int ALTURA_INICIAL_TELA_OCULTA = 255;
    private static final int LARGURA_INICIAL_TELA = 400;

        envioCupomFiscalView.getJbSeta1().addMouseListener(new MouseListener() {
        @Override
        public void mousePressed(MouseEvent e) {
            flagOcultar = !flagOcultar;
            envioCupomFiscalView.getJbImprimir().setVisible(flagOcultar);
            envioCupomFiscalView.getJbSemCupom().setVisible(flagOcultar);
            if (flagOcultar) {                  envioCupomFiscalView.getJbSeta1().setIcon(Constantes.Imagens.getSetaParaCima());
                envioCupomFiscalView.setBounds(0, 0, LARGURA_INICIAL_TELA, ALTURA_INICIAL_TELA_OCULTA);                 
            } else {                envioCupomFiscalView.getJbSeta1().setIcon(Constantes.Imagens.getSetaParaBaixo());
            envioCupomFiscalView.setPreferredSize(new Dimension(400, 320));
                envioCupomFiscalView.setBounds(0, 0, LARGURA_INICIAL_TELA, ALTURA_INICIAL_TELA_VISIVEL);
            }
        }

I tried using the setBounds and the setPreferredSize, but it didn’t work.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.