Pessoal quando eu clico no meu menuItem “Visualizar” era para meu frame adicionar um desktopPane e meu desktop add um internalFrame, até que esta adicionando porém ele nao preenche todo meu Frame e aparece apenas dois textFields, daí quando eu clico em cima do Desktop aparece ele todo…
Segue as classes…
[code]package com.teste.rev;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import com.teste.rev.JImagePanel.FillType;
public class Frame extends JFrame implements ActionListener{
JTextField text;
JLabel telefone;
JTextField textTel;
JButton buttonCadastrar;
JButton buttonLimpar;
JMenuBar menuBar;
JMenu menu;
JMenuItem menuItem;
JMenuItem visual;
JDesktopPane desktopPane;
public static void main(String[] args) {
try {
new Frame().setVisible(true);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Frame() throws IOException{
this.gui();
}
void gui() throws IOException{
BufferedImage bi = ImageIO.read(this.getClass().getResource("/icon/LOGO.png"));
JImagePanel imagePanel = new JImagePanel(bi);
imagePanel.setFillType(FillType.CENTER);
this.add(imagePanel);
this.menuBar = new JMenuBar();
this.menuBar.setVisible(true);
JMenu menu = this.getJMenu("File");
JMenuItem menuItem = this.getMenuItem("Sair");
JMenuItem menuItemVisual = this.getMenuItemVisual("Visualizar");
menu.add(menuItem);
menu.add(menuItemVisual);
this.menuBar.add(menu);
this.setJMenuBar(menuBar);
this.pack();
this.setMinimumSize(new Dimension(800,600));
this.setExtendedState(MAXIMIZED_BOTH);
}
private JMenu getJMenu(String nome){
this.menu = new JMenu(nome);
this.menu.setVisible(true);
return this.menu;
}
private JMenuItem getMenuItem(String nome){
this.menuItem = new JMenuItem(nome);
this.menuItem.setVisible(true);
this.menuItem.addActionListener(this);
return this.menuItem;
}
private JMenuItem getMenuItemVisual(String nome){
this.visual = new JMenuItem(nome);
this.visual.setVisible(true);
this.visual.addActionListener(this);
return this.visual;
}
private JDesktopPane getDesktopPane(){
this.desktopPane = new JDesktopPane();
return desktopPane;
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == this.menuItem){
this.dispose();
}
if(e.getSource() == this.visual){
JDesktopPane deskPanel = this.getDesktopPane(); // aqui adiciona um DesktopPane
deskPanel.add(new InternalFrame());
this.add(deskPanel); // adiciona um internalFrame
}
}
}
[/code]
Classe do InternalFrame…
[code]package com.teste.rev;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import net.miginfocom.swing.MigLayout;
public class InternalFrame extends JInternalFrame implements ActionListener{
JTextField text;
JLabel telefone;
JTextField textTel;
JButton buttonCadastrar;
JButton buttonLimpar;
JMenuBar menuBar;
InternalFrame(){
this.setVisible(true);
this.gui();
}
void gui(){
JPanel panel = this.getPanel();
JPanel panel2 = this.getPanel();
panel.setBorder(new TitledBorder("Cadastro de Usuários"));
MigLayout mig = new MigLayout();
panel.setLayout(mig);
this.add(panel);
panel2.setBorder(new TitledBorder("Dados Pessoais"));
panel2.setLayout(new MigLayout());
panel.add(panel2, "w :300:, h :200:");
JLabel labelNome = this.getLabel("Nome: ");
this.text = this.getText();
this.telefone = this.getLabel("Telefone: ");
this.textTel= this.getText();
JButton btCadastro = this.getButton("Cadastrar");
JButton btLimpar = this.getButtonLimpar("Limpar");
panel2.add(labelNome);
panel2.add(text, "span 2, grow x, wrap 10");
panel2.add(telefone);
panel2.add(textTel, "span 2, grow x, wrap 70");
panel2.add(btCadastro);
panel2.add(btLimpar, "cell 3 2, grow x, span 2");
this.pack();
}
private JButton getButton(String nome){
this.buttonCadastrar = new JButton(nome);
buttonCadastrar.setSize(new Dimension(100,80));
buttonCadastrar.setVisible(true);
this.buttonCadastrar.addActionListener(this);
return buttonCadastrar;
}
private JButton getButtonLimpar(String nome){
this.buttonLimpar = new JButton(nome);
this.buttonLimpar.setSize(new Dimension(100,80));
this.buttonLimpar.setVisible(true);
this.buttonLimpar.addActionListener(this);
return this.buttonLimpar;
}
private JLabel getLabel(String nome){
JLabel label = new JLabel(nome);
label.setVisible(true);
return label;
}
private JTextField getText(){
JTextField text = new JTextField();
text.setPreferredSize(new Dimension(100,20));
text.setVisible(true);
return text;
}
private JPanel getPanel(){
JPanel panel = new JPanel();
return panel;
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == this.buttonCadastrar){
if(!this.text.getText().isEmpty()){
JOptionPane.showMessageDialog(null,"Cadastro concluido com sucesso:\n" +
this.text.getText() +" " +this.textTel.getText());
}else{
JOptionPane.showMessageDialog(null, "Não há pessoas para cadastrar.");
}
return;
}
if (e.getSource() == this.buttonLimpar){
if(!this.text.getText().isEmpty()){
this.text.setText(null);
this.textTel.setText(null);
}else{
JOptionPane.showMessageDialog(null, "Não há dados para limpar.");
}
return;
}
}
}
[/code]