I'm having problems positioning components. I have a table, and 3 buttons, and I'm trying to position the buttons above the table centrally.
ItriedtouseFlowLayout
,andtheresultwasthis:
importjava.awt.Dimension;importjavax.swing.JButton;importjavax.swing.JComponent;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JScrollPane;importjavax.swing.JTable;publicclassPosicionaTabelaextendsJFrame{publicPosicionaTabela(){Tabelatab=newTabela();add(tab);setSize(700,400);setDefaultCloseOperation(EXIT_ON_CLOSE);setLocationRelativeTo(null);}publicstaticvoidmain(String[]args){newPosicionaTabela().setVisible(true);}}classTabelaextendsJPanel{privateJScrollPanejsp=newJScrollPane();privateJTabletabela=newJTable();privateJButtonbotao1=newJButton("1");
private JButton botao2 = new JButton("2");
private JButton botao3 = new JButton("3");
public Tabela() {
confgTabela();
}
private JComponent confgTabela() {
JPanel painel = new JPanel();
jsp.setViewportView(tabela);
jsp.setPreferredSize(new Dimension(400, 200));
add(jsp);
add(botao1);
add(botao2);
add(botao3);
return painel;
}
}