Tem como eu deixar um JInternalFrame modal?
JInternalFrame modal
4 Respostas
Uma simples busca no Google, e:
http://java.sun.com/developer/JDCTechTips/2001/tt1220.html
Cara vi este exemplo mas não consegui entender muito bem tb procurei por outros exemplos na net e nada ninguém tem um exemplo ou alguma dica de como devo proceder 
F
Ué, mas esse é um exemplo. Tu pegou o codigo e colocou pra rodar, fez uns debugs pra entender?
Se tu nao fez isso e simplesmente olhou pro código e pensou: “é, nao entendi” ai fica dificil mesmo.
]['s
Cara vi sim até já to conseguindo mudar algumas coisas to com ploblema agora par fechar a tela modal
/*
* ModalInternalFrame.java
*
* Created on 28 de Abril de 2005, 15:38
*/
package br.com.solutec.gestor.gui.internal.empresa;
/**
*
* @author Rodrigo Rocha
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.beans.*;
public class ModalInternalFrame extends javax.swing.JInternalFrame {
/** Creates new form ModalInternalFrame */
public ModalInternalFrame() {
initComponents();
}
public ModalInternalFrame(JRootPane rootPane, Component desktop) {
initComponents();
// create opaque glass pane
final JPanel glass = new JPanel();
glass.setOpaque(false);
// Attach mouse listeners
MouseInputAdapter adapter =
new MouseInputAdapter(){};
glass.addMouseListener(adapter);
glass.addMouseMotionListener(adapter);
// Define close behavior
PropertyChangeListener pcl =
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent
event) {
if (isVisible() &&
(event.getPropertyName().equals(
JOptionPane.VALUE_PROPERTY) ||
event.getPropertyName().equals(
JOptionPane.INPUT_VALUE_PROPERTY))) {
try {
setClosed(true);
} catch (PropertyVetoException ignored) {
}
ModalInternalFrame.this.setVisible(false);
glass.setVisible(false);
}
}
};
putClientProperty("JInternalFrame.frameType",
"optionDialog");
// Size frame
Dimension size = getPreferredSize();
Dimension rootSize = desktop.getSize();
setBounds((rootSize.width - size.width) / 2,
(rootSize.height - size.height) / 2,
size.width, size.height);
desktop.validate();
try {
setSelected(true);
} catch (PropertyVetoException ignored) {
}
// Add modal internal frame to glass pane
glass.add(this);
// Change glass pane to our panel
rootPane.setGlassPane(glass);
// Show glass pane, then modal dialog
glass.setVisible(true);
}
public void setVisible(boolean value) {
super.setVisible(value);
if (value) {
startModal();
} else {
stopModal();
}
}
private synchronized void startModal() {
try {
if (SwingUtilities.isEventDispatchThread()) {
EventQueue theQueue =
getToolkit().getSystemEventQueue();
while (isVisible()) {
AWTEvent event = theQueue.getNextEvent();
Object source = event.getSource();
if (event instanceof ActiveEvent) {
((ActiveEvent)event).dispatch();
} else if (source instanceof Component) {
((Component)source).dispatchEvent(
event);
} else if (source instanceof MenuComponent) {
((MenuComponent)source).dispatchEvent(
event);
} else {
System.err.println(
"Unable to dispatch: " + event);
}
}
} else {
while (isVisible()) {
wait();
}
}
} catch (InterruptedException ignored) {
}
}
private synchronized void stopModal() {
notifyAll();
}
/** 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.
*/
private void initComponents() {
jButton1 = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setTitle("Modal Internal Frame");
setPreferredSize(new java.awt.Dimension(400, 200));
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, java.awt.BorderLayout.CENTER);
pack();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
stopModal();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
stopModal();
}
Criado 28 de abril de 2005
Ultima resposta 28 de abr. de 2005
Respostas 4
Participantes 3