Olá
Tenho um Jpanel e estou tentando colocar ele no centro com .setLocation
Mas ele nao altera nada na posição
estou fazendo isso no load do form: jpnMenu.setLocation(300,300);
Alguma ideia de por que ele nem se mexe?
Olá
Tenho um Jpanel e estou tentando colocar ele no centro com .setLocation
Mas ele nao altera nada na posição
estou fazendo isso no load do form: jpnMenu.setLocation(300,300);
Alguma ideia de por que ele nem se mexe?
Se você estiver se referindo ao centro da tela pode usar:
panel.setLocationRelativeTo(null);
? nao tenho esse metodo
desde quando isso é um metodo?
jpnMenu.setLocationRelativeTo(null);
faz isso ai, vai dar certo! cara
eu disse
nao tenho, pra mim so aparecem dois tipos de Location
Location(Point p) e Location(x,y)
se eu fazer isso que voce me disse o compilador nao entende
tem como colocar seu codigo?
nao tem codigo alem de um Jframe normal
estou tentando por no Construtor, mas ele nao faz nada, nem se eu colocar as posições normais
fiz isso em um botao de teste:
jpnMenu.setLocation((jpnHint.getSize().width - jpnMenu.getSize().width)/2, 540);
no evento do botao ele funciona, porém, no construtor do frame nao.
olha em um pequeno exemplo de calculadora eu faço e dá certinho
public Calculadora() {
//Ajuste do formulário
setTitle("Calculadora");
setSize(245, 260);
setLocation(WIDTH, WIDTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
getContentPane().setLayout(null);
setLocationRelativeTo(null);
meu construtor esta assim
/** Creates new form JFPrincipal */
public JFPrincipal() {
initComponents();
setExtendedState(MAXIMIZED_BOTH);
jpnMenu.setLocation((jpnHint.getSize().width - jpnMenu.getSize().width)/2, 540);
}
se vc colocar apenas isso ja tem que fucionar e como sua IDE não copila?
[code]setLocationRelativeTo(null);[/code]
sim assim o compilador entende, mas mesmo assim, nao da certo

olha ai pq, ate o momento é simples o que queres fazer,fiz usando o NetBeans
[code]/*
/*
package exemplo;
/**
*
@author Vitor
*/
public class frmLayout extends javax.swing.JFrame {
/** Creates new form frmLayout */
public frmLayout() {
initComponents();
setLocationRelativeTo(null);
setResizable(false);
}
/** This method is called from within the constructor to
initialize the form.
WARNING: Do NOT modify this code. The content of this method is
always regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
//
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(51, 51, 255));
jLabel1.setBackground(new java.awt.Color(255, 255, 51));
jLabel1.setFont(new java.awt.Font(“Tahoma”, 3, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText(“Exemplo centro”);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(64, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(74, 74, 74)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(68, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}//
/**
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}[/code]
nao vai, é como eu disse, ele so nao funciona no construtor(ao iniciar form), em um evento de botao o codigo funciona
Vou olhar com mais atenção algumas coisa aqui
Vlews , att