Tela fica bagunçada se eu chamar mais de 2 JInternalFrame
4 respostas
jason_bourne
Pessoal,
Eu tenho um JFrame e dentro desse JFrame eu chamo um JInternalFrame para abrir uma janela com alguma funcionalidade. Só que quando eu abro um JInternalFrame e depois outro, a tela fica bagunçada e eu preciso mexer na janela para voltar ao normal. Como faço para resolver isso?
importjavax.swing.JInternalFrame;importjavax.swing.JDesktopPane;importjavax.swing.JMenu;importjavax.swing.JMenuItem;importjavax.swing.JMenuBar;importjavax.swing.JFrame;importjavax.swing.KeyStroke;importjava.awt.event.*;importjava.awt.*;/* * InternalFrameDemo.java requires: * MyInternalFrame.java */publicclassInternalFrameDemoextendsJFrameimplementsActionListener{JDesktopPanedesktop;publicInternalFrameDemo(){super("InternalFrameDemo");//Make the big window be indented 50 pixels from each edge//of the screen.intinset=50;DimensionscreenSize=Toolkit.getDefaultToolkit().getScreenSize();setBounds(inset,inset,screenSize.width-inset*2,screenSize.height-inset*2);//Set up the GUI.desktop=newJDesktopPane();//a specialized layered panecreateFrame();//create first "window"setContentPane(desktop);setJMenuBar(createMenuBar());//Make dragging a little faster but perhaps uglier.desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);}protectedJMenuBarcreateMenuBar(){JMenuBarmenuBar=newJMenuBar();//Set up the lone menu.JMenumenu=newJMenu("Document");menu.setMnemonic(KeyEvent.VK_D);menuBar.add(menu);//Set up the first menu item.JMenuItemmenuItem=newJMenuItem("New");menuItem.setMnemonic(KeyEvent.VK_N);menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.ALT_MASK));menuItem.setActionCommand("new");menuItem.addActionListener(this);menu.add(menuItem);//Set up the second menu item.menuItem=newJMenuItem("Quit");menuItem.setMnemonic(KeyEvent.VK_Q);menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,ActionEvent.ALT_MASK));menuItem.setActionCommand("quit");menuItem.addActionListener(this);menu.add(menuItem);returnmenuBar;}//React to menu selections.publicvoidactionPerformed(ActionEvente){if("new".equals(e.getActionCommand())){//newcreateFrame();}else{//quitquit();}}//Create a new internal frame.protectedvoidcreateFrame(){MyInternalFrameframe=newMyInternalFrame();frame.setVisible(true);//necessary as of 1.3desktop.add(frame);try{frame.setSelected(true);}catch(java.beans.PropertyVetoExceptione){}}//Quit the application.protectedvoidquit(){System.exit(0);}/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */privatestaticvoidcreateAndShowGUI(){//Make sure we have nice window decorations.JFrame.setDefaultLookAndFeelDecorated(true);//Create and set up the window.InternalFrameDemoframe=newInternalFrameDemo();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Display the window.frame.setVisible(true);}publicstaticvoidmain(String[]args){//Schedule a job for the event-dispatching thread://creating and showing this application's GUI.javax.swing.SwingUtilities.invokeLater(newRunnable(){publicvoidrun(){createAndShowGUI();}});}}
Micke
Eu costumo usar o seguinte para fazer chamadas por menus:
EditarProduto produtoEditar = new EditarProduto();
produto = new JInternalFrame("Seu Titulo", false, true, false, true);
produto.setContentPane(produtoEditar);
intDesk.add(produto); //intDesk é o nome da JFrame
produto.pack();
produto.setVisible(true);
Resolvi o problema da tela ficar bagunçada apenas trocando o JFrame por JDesktopPane. Mas agora tem outro problema. Se eu abro o segundo JInternalFrame, os dois voltam para o tamanho normal e eu gostaria que eles se mantivessem maximizados.
jason_bourne
resolvi o problema de maximização…era só manter essa ordem: