Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JInternalFrame;
- import javax.swing.JTextArea;
- public class CloseWindow extends javax.swing.JFrame {
- JTextArea tx;
- int i=1;
- public CloseWindow() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- tPane = new javax.swing.JTabbedPane();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- Crete = new javax.swing.JMenuItem();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jMenu1.setText("File");
- Crete.setText("Create");
- Crete.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- CreteActionPerformed(evt);
- }
- });
- jMenu1.add(Crete);
- jMenuBar1.add(jMenu1);
- setJMenuBar(jMenuBar1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(tPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(tPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void CreteActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- JInternalFrame internalFrame = new JInternalFrame();
- internalFrame.setName("Document"+i);
- internalFrame.setClosable(true);
- i++;
- internalFrame.setSize(700, 700);
- tx = new JTextArea();
- internalFrame.add(tx);
- tPane.add(internalFrame);
- internalFrame.setSize(internalFrame.getMaximumSize());
- internalFrame.pack();
- internalFrame.setVisible(true);
- }
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(CloseWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(CloseWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(CloseWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(CloseWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new CloseWindow().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JMenuItem Crete;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JTabbedPane tPane;
- // End of variables declaration
- internalFrame.addInternalFrameListener(new InternalFrameAdapter() {
- @Override
- public void internalFrameClosing(InternalFrameEvent e) {
- tPane.remove(internalFrame);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement