Ola Gente,
Algém sabe me dizer pq eu não consigo mudar a posição do meu JButton no JPanel,
Os atributos da GridBagConstraints não funcionam ( tirando o insets ).
O que estou fazendo de errado?
segue o codigo:
public class PanelPrincipal extends JPanel {
private GridBagConstraints c;
private JButton button;
public PanelPrincipal() {
GridBagLayout layout = new GridBagLayout();
setLayout(layout);
c = new GridBagConstraints();
button = new JButton("start");
c.fill = GridBagConstraints.REMAINDER;
c.ipadx = 40;
c.ipady = 0;
c.weightx = 1.0;
c.anchor = GridBagConstraints.PAGE_END;
c.insets = new Insets(0, 0, 0, 0); // apenas esse move o botão !
c.gridy = 5;
c.gridx = 5;
c.gridwidth = 1;
c.gridheight = 1;
add(button, c);
setBorder(BorderFactory.createLineBorder(Color.black));
}
@Override
public Dimension getPreferredSize() {
return new Dimension(1080, 657);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Draw Text
g.drawString("This is my custom Panel!", 10, 20);
}
}
public class TestePanels {
static PanelPrincipal panelPrincipal;
public static void main(String[] args) {
Runnable runnable = new Runnable() {
public void run() {
criaGui();
}
};
EventQueue.invokeLater(runnable);
}
private static void criaGui() {
JFrame frame = new JFrame();
frame.getContentPane().add(panelPrincipal = new PanelPrincipal(),
BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
Obrigado!