-1

I've searched about removing JInternalFrame's border, n I've got answer here. But now my query is after applying border to null, the border is not removed. As per second answer given in the question, I've tried to set border to Empty border n I've got success. And finally, my questions are as below.

  1. Why border is not removed even if I set border to null (e.g. jif.setBorder(null);)?
  2. I've set border to empty border (e.g. jif.setBorder(BorderFactory.createEmptyBorder());), but the titlebar of JInternalFrame is still visible, how to hide JInternalFrame's Title with its border?

Edited by Girish

My Code sample is as below:

package com.laxmiagencies.ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class MDIParent extends JFrame {

    private static final long serialVersionUID = -7911142498378226657L;

    public JDesktopPane jdp;

    private JLabel apptitle;

    private MDIListener listen;

    public JMenuBar menubar;

    private boolean islogin;

    private boolean enablelogin;

    private JMenuItem mnuabout;

    public MDIParent()
    {
        super();
        enablelogin=false;
        init();
    }

    public MDIParent(String apptitle)
    {
        super(apptitle);
        enablelogin=false;
        init();
    }

    public MDIParent(String apptitle, boolean enablelogin)
    {
        super(apptitle);
        this.enablelogin=enablelogin;
        init();
    }

    public MDIParent(boolean enablelogin)
    {
        super();
        this.enablelogin=enablelogin;
        init();
    }

    public boolean isLoginEnabled()
    {
        return enablelogin;
    }

    public void setLoginEnabled(boolean enablelogin)
    {
        this.enablelogin=enablelogin;
        this.islogin=!this.enablelogin;
    }

    public boolean isLoggedIn()
    {
        return islogin;
    }

    private void init()
    {
        listen=new MDIListener();

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        jdp=new JDesktopPane();
        jdp.setBounds(0, 0, getWidth(), getHeight());
        jdp.addContainerListener(listen);
        add(jdp);

        setBounds(0, 0, Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height-50);

        apptitle=new JLabel(getTitle());
        apptitle.setBounds(20, 50, getWidth()-30, 70);
        jdp.add(apptitle);

        menubar=new JMenuBar();
            mnuabout=new JMenuItem("About Us");
            mnuabout.addActionListener(listen);
            menubar.add(mnuabout);
        setJMenuBar(menubar);

        islogin=!enablelogin;

        addComponentListener(listen);
    }

    public void setAppTitle(String apptitle)
    {
        setTitle(apptitle);
        this.apptitle.setText(apptitle);
    }

    public void setTitleFont(Font font)
    {
        apptitle.setFont(font);
    }

    public void setTitleForeColor(Color color)
    {
        apptitle.setForeground(color);
    }

    //INFO Listener Class
    private class MDIListener implements ComponentListener, ActionListener, ContainerListener
    {
        //INFO Used Methods
        @Override
        public void actionPerformed(ActionEvent e)
        {
            if(e.getSource()==mnuabout)
            {
                AboutUs abt=new AboutUs();
                jdp.add(abt);
                abt.setVisible(true);
            }
        }

        @Override
        public void componentResized(ComponentEvent e) 
        {
            jdp.setBounds(0, 0, getWidth(), getHeight());
            for(JInternalFrame frame:jdp.getAllFrames())
            {
                frame.setSize(jdp.getWidth()-15, jdp.getHeight()-60);
            }
        }

        @Override
        public void componentShown(ComponentEvent e)
        {
            if(enablelogin)
            {
                if(!islogin)
                {
                    setEnabled(false);
                    LoginWindow login=new LoginWindow();
                    login.setUndecorated(true);
                    login.setAlwaysOnTop(true);
                    login.setVisible(true);
                }
            }
        }

        @Override
        public void componentAdded(ContainerEvent e)
        {
            if(e.getChild() instanceof JInternalFrame)
            {
                JInternalFrame child=(JInternalFrame)e.getChild();
                child.setBounds(0, 0, jdp.getWidth()-15, jdp.getHeight()-60);
                child.setBorder(javax.swing.BorderFactory.createEmptyBorder());
            }
        }

        //INFO Unused methods 
        @Override
        public void componentRemoved(ContainerEvent e){}

        @Override
        public void componentHidden(ComponentEvent e){}

        @Override
        public void componentMoved(ComponentEvent e){}
    }
}

The JInternalFrame code is as follows

import javax.swing.BorderFactory;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;

public class AboutUs extends JInternalFrame {

    /**
     * 
     */
    private static final long serialVersionUID = -4542063025572303166L;

    private JPanel panel;

    public AboutUs()
    {
        setTitle("About Us");
        setLayout(null);

        panel=new JPanel();
            panel.setSize(200, 200);
            panel.setBorder(BorderFactory.createTitledBorder("About Us"));
        add(panel);
        setMaximizable(true);
    }

    public JPanel getPanel()
    {
        return panel;
    }
}

I've another question one:
3. How to disable of dragging JInternalFrame? i.e. the JInternalFrame must not be moved by user.

Community
  • 1
  • 1
Girish
  • 213
  • 2
  • 13
  • 2
    can you post your code? – Jegg Jul 09 '15 at 13:32
  • @Jegg I already have posted my code in brackets. If you need full code, then its not necessary because code is so simple and any java developer can understand the code, that's why I've not posted the code. – Girish Jul 09 '15 at 14:03
  • 2
    @Girish, The code `IS` necessary. We can't tell how you actually use that code. We need a proper [SSCCE](http://sscce.org/) that demonstrates the problem. That is create a frame, add a JDesktopPane to the frame and add a JInternalFrame to the desktop pane. The code will be about 20-30 lines of code and will show us exactly what you are doing. By the way, setBorder( null ) works for me. That is why we need your code because the problem is your code, not the two statements you posted. – camickr Jul 09 '15 at 14:23

1 Answers1

3

How to remove JInternalFrame's Border?

You use:

internalFrame.setBorder( null );

This works for me using JDK8 in Windows 7. If it doesn't work for you post a proper SSCCE.

how to hide JInternalFrame's Title with its border?

You can use the following. It will still leave a little border at the top if the internal frame to allow you to drag the frame around

internalFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);

If you don't need the dragging functionality then real question is why are you trying to remove the border? The point if using an internal frame is to allow the user to freely move the frame around the desktop by dragging the frame.

If all you need is a panel without a Border, then use a JPanel and add the panel to a parent panel. There is no need for the complexity of a JDestopPane/JInternalPane if you are not going to use those features.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • I've tried the code given by you (`internalFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);`). But not working. Another one thing, I'm using JDK7 on windows 7 – Girish Jul 10 '15 at 04:29