How do I force the JInternalFrame to fill the Container and disable the drag and drop functionality?

I am working on a project, there is a JInternalFrames on the mainframe. Now we have to let them be JFrame. I am considering using a JFrame to store a JInternalFrame. The problem is that the title of the inner frame is there and the user can drag and drop it.

Is there a way to make the inner framework work like a panel in a JFrame? After searching the web, I found that someone is deleting the title.

Do you have a good idea?

Thanks you!

update: I may have been wrong. The real problem is that the JInternal frame can't get out of the main frame, or in any way make it look like it's part of the frame?

+3


source to share


2 answers


Is there a way to make the inner framework work like a panel in a JFrame

I'm not sure what you mean by panel, but I guess how JPanel

? Sure you can, but why, would be my question if you don't want some kind of fast floating panel, but as you say, you don't want to drag it around? So I'm a little unsure about your motives and make me tired of answering ....

The problem is the Internalframe title bar exists

Well here is the code for removing titlepane (found here ):

//remove title pane http://www.coderanch.com/t/505683/GUI/java/JInternalframe-decoration
BasicInternalFrameTitlePane titlePane =(BasicInternalFrameTitlePane)((BasicInternalFrameUI)jInternalFrame.getUI()).getNorthPane();
jInternalFrame.remove(titlePane);

      

and the user can drag and drop it.

And I found this to make it JInternalFrame

inherent, by deleting MouseListener

that makes it movable, but it's important to note that it doesn't need to be removed MouseListener

as the method used to exclude it will result in a deletion NorthPane

that's added to MouseListener

, so it's unnecessary to remove it yourself.



//remove the listeners from UI which make the frame move
BasicInternalFrameUI basicInternalFrameUI = ((javax.swing.plaf.basic.BasicInternalFrameUI) jInternalFrame.getUI());
for (MouseListener listener : basicInternalFrameUI.getNorthPane().getMouseListeners()) {
    basicInternalFrameUI.getNorthPane().removeMouseListener(listener);
}

      

And as your name suggests:

how to JInternalFrame

fill the container

Just type setSize(int width,int height)

on JInternalFrame

with parameters JDesktopPane

width

and height

( JDesktopPane

will be sized using an override getPreferredSize()

).

Which will give us this:

enter image description here

import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.event.MouseListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import javax.swing.plaf.basic.BasicInternalFrameUI;

/**
 *
 * @author David
 */
public class Test {

    public Test() {
        createAndShowGUI();
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Test();

            }
        });
    }

    private void createAndShowGUI() throws HeadlessException {
        JFrame frame = new JFrame();
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        final JDesktopPane jdp = new JDesktopPane() {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(300, 300);
            }
        };

        frame.setContentPane(jdp);
        frame.pack();

        createAndAddInternalFrame(jdp);

        frame.setVisible(true);
    }

    private void createAndAddInternalFrame(final JDesktopPane jdp) {
        JInternalFrame jInternalFrame = new JInternalFrame("Test", false, false, false, false);
        jInternalFrame.setLocation(0, 0);
        jInternalFrame.setSize(jdp.getWidth(), jdp.getHeight());

        //remove title pane http://www.coderanch.com/t/505683/GUI/java/JInternalframe-decoration
        BasicInternalFrameTitlePane titlePane = (BasicInternalFrameTitlePane) ((BasicInternalFrameUI) jInternalFrame.getUI()).getNorthPane();
        jInternalFrame.remove(titlePane);

        /*
         //remove the listeners from UI which make the frame move
         BasicInternalFrameUI basicInternalFrameUI = ((javax.swing.plaf.basic.BasicInternalFrameUI) jInternalFrame.getUI());
         for (MouseListener listener : basicInternalFrameUI.getNorthPane().getMouseListeners()) {
         basicInternalFrameUI.getNorthPane().removeMouseListener(listener);
         }
         */
        jInternalFrame.setVisible(true);

        jdp.add(jInternalFrame);
    }
}

      

+4


source


Considering your requirements, I suggest you just use the JPanel

content area JFrame

.



+2


source







All Articles