Colocar um botao em JInternalFrame do tipo cancelar

1 resposta
G

Seguinte duvida:

Quero colocar um botao em um JInternalFrame:
JButton botao = new JButton(“Cancelar”);

Esse botao ira fazer a mesma funcao que a cruz da janela do JInternalFrame faz, ou seja, eu clicando no botao, a janela sera fechada (Close Window), o detalhe e que e um
JInternalFrame.

Como faco isso?

1 Resposta

R

Fala GateCrasher !!! :slight_smile:

esta aí a solução (metodo “.dispose()”):

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class CloseInternalFrame extends JFrame {
	
	private JInternalFrame internalFrame;
	private JButton		   botaoCancelar;
	
	public CloseInternalFrame() {
		botaoCancelar = new JButton("Cancelar");
		
		internalFrame = new JInternalFrame("Frame Interna", true, true, true, true);
		internalFrame.getContentPane().add(botaoCancelar);
		
		botaoCancelar.addActionListener(new ActionListener() {
											public void actionPerformed(ActionEvent event) {
												internalFrame.dispose();
											}
										});

		getContentPane().add(internalFrame);
		
		internalFrame.getContentPane().setLayout(new FlowLayout());
		internalFrame.setSize(200, 200);
		internalFrame.show();
				
		setSize(640, 480);
		show();
	}
	
	public static void main(String[] args) {
		CloseInternalFrame closeInternalFrame = new CloseInternalFrame();
	}
}

até mais, Thiago.

Criado 12 de novembro de 2003
Ultima resposta 16 de nov. de 2003
Respostas 1
Participantes 2