3 Replies Latest reply on Feb 22, 2010 10:59 PM by 843807

    problem  in maximize JInternalFrame

    843807
      Here when i press show button JInternalframe contains JTable appear . But i want JinternalFrame to full the screen so i used :
              try {
                  internalFrame.setMaximum(true);
              } catch (PropertyVetoException ex) {
                  ex.printStackTrace();
              }
      but i t give me : Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at javax.swing.DefaultDesktopManager.maximizeFrame(DefaultDesktopManager.java:115)

      code:
      --------------
      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import java.awt.FlowLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.beans.PropertyVetoException;
      import java.sql.SQLException;
      import javax.swing.JButton;
      import javax.swing.JDesktopPane;
      import javax.swing.JFrame;
      import javax.swing.JInternalFrame;
      import javax.swing.JPanel;
      import javax.swing.JScrollPane;
      import javax.swing.JTable;
      import javax.swing.ScrollPaneConstants;
      
      public class TestJtable extends JFrame {
      
          private JPanel mainPanel, buttonPanel;
          private JButton[] buttons;
          private final String[] BUTTONNAMES = {"showButton", "insertButton", "searchButton", "updateButton", "deletebutton"};
          private JInternalFrame internalFrame;
          private JDesktopPane desktopPane;
          private JTable table;
          private JScrollPane scrollPane;
          private MyActionListener myActionListener;
      
          public TestJtable() throws ClassNotFoundException, SQLException {
              intializingPanels();
              intializingbuttons();
              table = new JTable(3,4);
              scrollPane = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
              getContentPane().add(mainPanel);
          }
      
          public static void main(String[] args) throws SQLException, ClassNotFoundException {
              TestJtable testJtable = new TestJtable();
              testJtable.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              testJtable.setSize(new Dimension(600, 300));
              testJtable.setLocationRelativeTo(null);
              testJtable.setVisible(true);
              testJtable.setExtendedState(MAXIMIZED_BOTH);
          }
      
          private void intializingPanels() {
              mainPanel = new JPanel(new BorderLayout());
              buttonPanel = new JPanel(new FlowLayout());
      
          }
      
          private void intializingbuttons() {
              myActionListener = new MyActionListener();
              buttons = new JButton[BUTTONNAMES.length];
              for (int i = 0; i < BUTTONNAMES.length; i++) {
                  buttons[i] = new JButton(BUTTONNAMES);
      buttons[i].addActionListener(myActionListener);
      buttonPanel.add(buttons[i]);
      mainPanel.add(buttonPanel, BorderLayout.NORTH);
      }
      }

      private void intializingInternalDeskTop() {
      JPanel panel = new JPanel(new BorderLayout());
      panel.add(scrollPane, BorderLayout.CENTER);
      /////////////////////////////////////////////////////////////
      internalFrame = new JInternalFrame("", true, true, true);
      internalFrame.setSize(500, 500);
      internalFrame.add(panel);
      internalFrame.setVisible(true);
      try {
      internalFrame.setMaximum(true);
      } catch (PropertyVetoException ex) {
      ex.printStackTrace();
      }
      //////////////////////////////////////////////////////////////
      desktopPane = new JDesktopPane();
      desktopPane.setOpaque(false);
      desktopPane.setEnabled(true);
      desktopPane.add(internalFrame);
      mainPanel.add(desktopPane, BorderLayout.CENTER);
      }

      private class MyActionListener implements ActionListener {

      public void actionPerformed(ActionEvent e) {
      if (e.getSource() == buttons[0]) {
      intializingInternalDeskTop();

      }
      }
      }
      }
      Thanks in advance                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
        • 1. Re: problem  in maximize JInternalFrame
          camickr
          The frame hasn't been added to the desktop.
          • 2. Re: problem  in maximize JInternalFrame
            843807
            h2. You are using non-null layout managers!!! Hooray!!!

            As to your problem, perhaps the API will help you out. If you look up what setMaximum does, it maximizes the internal frame so as "to fully fit the JDesktopPane area associated with the JInternalFrame."

            So at the time you call this method, which non-null JDesktopPane is associated with your JInternalFrame? Answer none. Possible solution: call this setMaximum method after you've added the JInternalFrame to the JDesktopPane.

            Much luck!
            • 3. Re: problem  in maximize JInternalFrame
              843807
              yes , it is worked now .


              This is the right code:
              ---------------------------------------
               private void intializingInternalDeskTop() {
                      JPanel panel = new JPanel(new BorderLayout());
                      panel.add(scrollPane, BorderLayout.CENTER);
                      /////////////////////////////////////////////////////////////
                      internalFrame = new JInternalFrame("", true, true, true);
                      internalFrame.setSize(500, 500);
                      internalFrame.add(panel);
                      internalFrame.setVisible(true);
                             //////////////////////////////////////////////////////////////
                      desktopPane = new JDesktopPane();
                      desktopPane.setOpaque(false);
                      desktopPane.setEnabled(true);
                      desktopPane.add(internalFrame);
                      try {
                          internalFrame.setMaximum(true);
                      } catch (PropertyVetoException ex) {
                          ex.printStackTrace();
                      }
              
                      mainPanel.add(desktopPane, BorderLayout.CENTER);
                  }
              Many Thanks