JInternalFrame e JDesktopPane

10 respostas
marcos2205

Boa Noite

Pessoal não entendo, eu preciso criar um JDesktopPane e depois add a JInternalFrame nela ?
e como “ligar” um item do menu a uma internalframe para abrir somente ao clicar no menu referente ??

Obrigado

10 Respostas

C

Na verdade vc insere um desktopPane dentro de um JFrame.
Pra abrir um internalFrame quando clicar em um menu, vc deve adicionar um evento neste menu, para que quando ele receba o clique, ele crie um objeto JInternalFrame e exiba-o.

marcos2205

Certo, mas eu coloco e da erro!

JDesktopPane op = new JDesktopPane("op");
        frame.add(op);
marcoslogan
JDesktopPane desktop = new JDesktopPane();//aqui você chama o construtor padrão.
   desktop.setSize(400,900);//aqui estou colocando um valor qualquer.
   

   this.add(desktop);//considerando que a classe extenda a classe JFrame.


   No clique botão você coloca assim.

   CadFuncionario cadfunc = new CadFuncionario();//construtor do JInternalFrame, mas não se esqueça de deixar o método setVisible para true.
   desktop.add(cadfunc)//desktop é uma variável global, pois terei de usá-la várias vezes no meu form.
   desktop.setVisible(true);//Mostra o desktop no form principal

A cada clique do botão, você adiciona do JInternalFrame ao JDesktopPane, entendeu?

É fácil!

Espero ter ajudado.

marcos2205

Não entendi muito menos fazer essa parte!

No clique botão você coloca assim.

CadFuncionario cadfunc = new CadFuncionario();//construtor do JInternalFrame, mas não se esqueça de deixar o método setVisible para true. desktop.add(cadfunc)//desktop é uma variável global, pois terei de usá-la várias vezes no meu form. desktop.setVisible(true);//Mostra o desktop no form principal

Podem me ajudar? Obrigadoo!

L

pode postar o erro?

marcos2205

erro nenhum…apenas coloco o ultimo codigo postado e nada acontece!

Felagund

troque

desktop.setVisible(true);//Mostra o desktop no form principal

por

cadfunc.setVisible(true);
marcos2205

galera eu so tenho isso…

JFrame frame = new JFrame("teste");
        frame.setVisible(true);
        frame.setSize(1000,700);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JMenuBar menu = new JMenuBar();
        frame.setJMenuBar(menu);

        JMenu imoveis = new JMenu("Imóveis...");
        menu.add(imoveis);

        JMenuItem casa = new JMenuItem("Casas");
        imoveis.add(casa);

        JDesktopPane dp = new JDesktopPane();
        dp.setSize(1000,700);
        frame.add(dp);
        dp.setVisible(true);

quando eu clicar em casas…gostaria que aparecesse outra tela…

P

problemas no jdesktoppane eu mando fechar um jinternal frame e ele fecha na hora que mando abrir de novo ele da um erro bizarro

xception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.Vector.elementData(Vector.java:730)
	at java.util.Vector.elementAt(Vector.java:473)
	at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:665)
	at automaticnewsletter.interfacing.DB.consultadb(DB.java:42)
	at automaticnewsletter.interfacing.Desk.abreRemessa(Desk.java:201)
	at automaticnewsletter.interfacing.Desk.jMenuItem4ActionPerformed(Desk.java:157)
	at automaticnewsletter.interfacing.Desk.access$000(Desk.java:23)
	at automaticnewsletter.interfacing.Desk$1.actionPerformed(Desk.java:101)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
	at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
	at java.awt.Component.processMouseEvent(Component.java:6505)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
	at java.awt.Component.processEvent(Component.java:6270)
	at java.awt.Container.processEvent(Container.java:2229)
	at java.awt.Component.dispatchEventImpl(Component.java:4861)
	at java.awt.Container.dispatchEventImpl(Container.java:2287)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
	at java.awt.Container.dispatchEventImpl(Container.java:2273)
	at java.awt.Window.dispatchEventImpl(Window.java:2719)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
	at java.awt.EventQueue.access$000(EventQueue.java:102)
	at java.awt.EventQueue$3.run(EventQueue.java:662)
	at java.awt.EventQueue$3.run(EventQueue.java:660)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.awt.EventQueue$4.run(EventQueue.java:676)
	at java.awt.EventQueue$4.run(EventQueue.java:674)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
CONSTRUÍDO COM SUCESSO (tempo total: 14 segundos)
P

esqueci de enviar a classe :

package automaticnewsletter.interfacing;


import automaticnewsletter.createNews.News;
import automaticnewsletter.createNews.Newsletter_interface;
import automaticnewsletter.createNews.newsletter;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


/**
 *
 * @author pedro
 */
public class Desk extends javax.swing.JFrame implements Newsletter_interface // , SmbInterface
{

    /**
     * Creates new form Desk
     */
    public Desk()   //construtor
    {
        this.setTitle("Newsletter");
        init();
    }
      
    private void init() // inicia os componentes da classe
    {        
        initComponents();
        getDesktopSize();
        this.setVisible(true);     
    }          
    
    private void getDesktopSize() //auto-redimensionamento
    {
        _c= getContentPane();  
        tela = Toolkit.getDefaultToolkit().getScreenSize();  
        this.setSize(tela.width-50, tela.height-100);   
        //dc.gc.setTime(dc.d);  // 0=janeiro 6= julho 
     }
   
      
    /**
     * 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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 774, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
        );

        jMenu1.setText("Arquivo");

        jMenuItem1.setText("Configurações");
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Sair");
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu3.setText("Remessa");

        jMenuItem4.setText("Gerar");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem4);

        jMenuItem5.setText("Enviar");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem5);

        jMenuBar1.add(jMenu3);

        jMenu2.setText("Sobre");

        jMenuItem3.setText("Sobre");
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        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();
    }// </editor-fold>                        

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
         if(evt.getSource()==jMenuItem4)
         {
            
             if(jDesktopPane1.getComponentCount()>0)
             {
                jDesktopPane1.removeAll();  
                 
             }
             else
             {    
                 
                 abreRemessa();
             }
         }
         
         /*
          * 
          */
    }                                          

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        if(evt.getSource()==jMenuItem5)
        {   
            /*
            String novo= dc.getNextNews("15","segunda");
            int _dia, mes; //2012-07-12           
            mes = Integer.parseInt(novo.substring(6,7));
            _dia=Integer.parseInt(novo.substring(9,10));  
            dc.getFeriado(mes, _dia);*/
            if(jDesktopPane1.getComponentCount()>0)
            {
                    rm.getFiles();
                    boolean flag=false;
                    if(flag==true)
                    {                       
                        JOptionPane.showMessageDialog(null, "E-mails enviados con sucesso!!!","Info",JOptionPane.INFORMATION_MESSAGE);                        
                    }
                    else
                    {
                        JOptionPane.showMessageDialog(null, "Não foi possivel enviar o email","Erro 04",JOptionPane.INFORMATION_MESSAGE);
                    }
            }
            else
            {
                    System.out.println("null");
                    JOptionPane.showMessageDialog(null, "Por favor vá em no menu 'Remessa'\ne clique na opção 'Gerar' \n e depois clique em 'Enviar'", "Erro 02", WIDTH);
            }
        }        
    }                                          

    
    private void abreRemessa()
    {
        rm = new Remessa();
        con.consultadb("Select * from tb_canal_hotsite order by nome_canal");                  
        rm.jButton2.setSize(jDesktopPane1.getWidth()-150, 25);
        rm.setSize(jDesktopPane1.getWidth()-110, jDesktopPane1.getHeight()-110);
        rm.jTable1.setModel(new DefaultTableModel());    
        rm.jTable1.setModel(con.modelo);
        rm.setVisible(true);                  
        jDesktopPane1.add(rm); 
       
    }
Criado 8 de março de 2010
Ultima resposta 18 de jul. de 2012
Respostas 10
Participantes 6