Create Jlabel under image

Asked

Viewed 88 times

2

I created a 672x750 Jpanel and put a 672x672 image inside it. I need to put texts under the image, in the space that remains. Is there any way to create a Jlabel and position it below the image? I tried, but they take up all available space

public class ContainerDeJanelas extends JFrame {

    JLabel infoTotal = new JLabel("Tempo total da batalha (em milissegundos): ");
    JLabel infoCasa = new JLabel("Tempo da Batalha em");
    JLabel infoDragaoBatalha = new JLabel("Dragões usados na Batalha de");

    public ContainerDeJanelas() {
        add(new MapaInterface());
        setTitle("Heurística Game of Thrones");
        //tamanho da tela
        setSize(672, 750);
        //usuario nao pode redimensionar a tela
        //setResizable(false);
        add(infoTotal);
        add(infoCasa);
        add(infoDragaoBatalha);
        //evento ao clicar em fechar
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //onde a janela vai aparecer (null = centro)
        setLocationRelativeTo(null);

        setVisible(true);
    }
}

I need infoTotal to stay below Mapainterface and infoCasa to stay below infoTotal. Infodragao battle has to stay in the bottom right corner. It has how to do this?

  • Which layout manager are you using? Add a [mcve] so you can reproduce the problem.

1 answer

0

have several ways , if you want to do something simple use setLayout() if you want to have more control over your layout create Jpanel and add() later in your frame here you find the list of layouts java layouts

public class ContainerDeJanelas extends JFrame {

JLabel infoTotal = new JLabel("Tempo total da batalha (em milissegundos): ");
JLabel infoCasa = new JLabel("Tempo da Batalha em");
JLabel infoDragaoBatalha = new JLabel("Dragões usados na Batalha de");

public ContainerDeJanelas() {
    add(new MapaInterface());
    setTitle("Heurística Game of Thrones");
    //tamanho da tela
    setSize(672, 750);
    //usuario nao pode redimensionar a tela
    //setResizable(false);

    setLayout(new LayoutQueVocePreferir());
    // conferir o link como nao sei como vc quer mostar os label 
    // nao tem como eu saber qual vc prefere usar

    add(infoTotal);
    add(infoCasa);
    add(infoDragaoBatalha);
    //evento ao clicar em fechar
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //onde a janela vai aparecer (null = centro)
    setLocationRelativeTo(null);

    setVisible(true);
  }
}
  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - From Review

  • the answer part is only one line he has to add, that line was mentioned in the answer , there is no way I know which layout manager he has to use because I do not know how he display the Abels , so I believe that the "essential parts" were mentioned in the answer .

  • For the context of the answer, from yes to suggest a layout, just reread the text.

Browser other questions tagged

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