1
I would like to have my canvas divided into at least two parts, at the top I will add some fields, and at the bottom, a JTabbedPane
with a few tabs. The problem is that I don’t know how to do this, I can only make Jtabbedpane occupying the entire screen.
Follow an image to illustrate:
Canvas:
package tabbedpane;
import java.awt.Dimension;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class Tela extends JFrame {
JTabbedPane tabbedPane = new JTabbedPane();
public Tela() {
setTitle("Apenas um EXEMPLO");
tabbedPane.addTab("Página 1", painel1());
tabbedPane.addTab("Página 2", painel2());
add(tabbedPane);
setResizable(false);
setVisible(true);
setSize(600, 500);
setLocationRelativeTo(null);
setMinimumSize(new Dimension(getWidth(), getHeight()));
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public static void main(String[] args) {
Tela tela = new Tela();
}
public JComponent painel1() {
JPanel painel1 = new JPanel();
JLabel label1;
label1 = new JLabel("Página 1");
painel1.add(label1);
return painel1; // retorna painel.
}
public JComponent painel2() {
JPanel painel2 = new JPanel();
JLabel label2;
label2 = new JLabel("Página 2");
painel2.add(label2);
return painel2;
}
}
Wow, thank you so much !
– user60035
@Joaopedro :)
– user28595
@Gustavosantos has no secret, just follow the reasoning of the changes I highlighted, perform this code and see the same reasoning applied to your doubt(has additional comments in the code).
– user28595
@Gustavosantos the ideal is always to distribute components through containers, facilitates repositioning something, as in your case. There is no way to suggest anything without seeing and simulating the problem, maybe it is the case to create a question even with an example that is reproducible.
– user28595