Dúvida Tamanho JInternalFrame

3 respostas
A

Pessoal, é o seguinte.
Crei um Frame principal coloquei nele
um JDesktopPane. Estou chamando um JInternalFrame.
Quando chamo o JInternalFrame ele abre maximizado, ocupando todo
o tamanho do JDesktopPane.
Só que no construtor dele eu defini outros tamanhos.
Me parece que o método pack(), do Frame principal é que
faz ele ocupar todo o tamanho do JDesktopPane, mas nao sei
como alterar isto.

Alguém tem um exemplo, uma solução?

Valeu.

package projetoteste; 

/** 
* 
* @author andersonc 
*/ 
public class formMunicipios extends javax.swing.JInternalFrame { 

/** Creates new form formMunicipios */ 
public formMunicipios() { 
initComponents(); 
iniciar (); 
} 

private void iniciar(){ 

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 
setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300); 
} 

private void initComponents() { 
jToolBar1 = new javax.swing.JToolBar(); 
jButton1 = new javax.swing.JButton(); 
jButton2 = new javax.swing.JButton(); 
jButton3 = new javax.swing.JButton(); 
jButton4 = new javax.swing.JButton(); 

getContentPane().setLayout(null); 

jButton1.setText("Sair"); 
jToolBar1.add(jButton1); 

jButton2.setText("Salvar"); 
jToolBar1.add(jButton2); 

jButton3.setText("Novo"); 
jToolBar1.add(jButton3); 

jButton4.setText("Proxmo"); 
jButton4.setPreferredSize(new java.awt.Dimension(47, 30)); 
jButton4.addActionListener(new java.awt.event.ActionListener() { 
public void actionPerformed(java.awt.event.ActionEvent evt) { 
jButton4ActionPerformed(evt); 
} 
}); 

jToolBar1.add(jButton4); 

getContentPane().add(jToolBar1); 
jToolBar1.setBounds(0, 0, 190, 30); 

pack(); 
} 

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { 
// TODO add your handling code here: 
} 


// Variables declaration - do not modify 
private javax.swing.JButton jButton1; 
private javax.swing.JButton jButton2; 
private javax.swing.JButton jButton3; 
private javax.swing.JButton jButton4; 
private javax.swing.JToolBar jToolBar1; 
// End of variables declaration 

}
package projetoteste; 

import javax.swing.*; 

public class formPrincipal extends javax.swing.JFrame { 
JInternalFrame formun; 
/** Creates new form formPrincipal */ 
public formPrincipal() { 
initComponents(); 
iniciar(); 
} 
private void iniciar (){ 
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 
setBounds(0, 0, screenSize.width, screenSize.height); 

formun = new formMunicipios(); 
getContentPane().add(formun); 


} 

private void initComponents() { 
jDesktopPane1 = new javax.swing.JDesktopPane(); 
jMenuBar1 = new javax.swing.JMenuBar(); 
jMenu1 = new javax.swing.JMenu(); 
jItemSair = new javax.swing.JMenuItem(); 
jMenu2 = new javax.swing.JMenu(); 
jitemMun = new javax.swing.JMenuItem(); 

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
jDesktopPane1.setBackground(java.awt.Color.white); 
getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER); 

jMenu1.setText("Arquivo"); 
jItemSair.setText("Sair"); 
jItemSair.addActionListener(new java.awt.event.ActionListener() { 
public void actionPerformed(java.awt.event.ActionEvent evt) { 
jItemSairActionPerformed(evt); 
} 
}); 

jMenu1.add(jItemSair); 

jMenuBar1.add(jMenu1); 

jMenu2.setText("Cadastro"); 
jitemMun.setText("Municipios"); 
jitemMun.addActionListener(new java.awt.event.ActionListener() { 
public void actionPerformed(java.awt.event.ActionEvent evt) { 
jitemMunActionPerformed(evt); 
} 
}); 

jMenu2.add(jitemMun); 

jMenuBar1.add(jMenu2); 

setJMenuBar(jMenuBar1); 

pack(); 
} 

private void jitemMunActionPerformed(java.awt.event.ActionEvent evt) { 
formun.setVisible(true); 
} 

private void jItemSairActionPerformed(java.awt.event.ActionEvent evt) { 
System.exit(0); 
} 


public static void main(String args[]) { 
java.awt.EventQueue.invokeLater(new Runnable() { 
public void run() { 
new formPrincipal().setVisible(true); 
} 
}); 
} 

// Variables declaration - do not modify 
private javax.swing.JDesktopPane jDesktopPane1; 
private javax.swing.JMenuItem jItemSair; 
private javax.swing.JMenu jMenu1; 
private javax.swing.JMenu jMenu2; 
private javax.swing.JMenuBar jMenuBar1; 
private javax.swing.JMenuItem jitemMun; 
// End of variables declaration 

}

[color=red]Mensagem do Moderador: ao postar codigos utilize as tags [ code ] [ /code ][/color]

3 Respostas

_Renatu

opa…

assim… ou voce usa setBounds… ou vc usa pack…

quando voce usa o metodo pack… ele deixa a janela do menor tamanho, respeitando o menor tamanho possivel dos componentes na tela…

pode ser q no seu caso seja o tamanho maximizado…

fmeyer

Quando vc for postar codigo,
coloque-o entre as tags [ code ] e [ /code ],
assim ele ficará identado.

A

Só que eu já estou usando
o setBounds no construtor do meu
JInternalFrame, mas mesmo assim ele vem de outro tamanho.

private void iniciar(){ 

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 
setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300); 
}

[color=red]Mensagem do Moderador: Ao postar codigos utilize as tags [ code ] [ /code ].[/color]

Criado 16 de agosto de 2005
Ultima resposta 16 de ago. de 2005
Respostas 3
Participantes 3