2

I started to create a swing java application and I'm using JInternalFrame in it when I, suddenly, noticed this design issue in the JInternalFrame:
enter image description here

Is it a design bug or something ?
And is there a solution for it ? Here is my code:

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TestJInternalFrame extends JFrame {
    public TestJInternalFrame() {

        JDesktopPane desktopPane = new JDesktopPane();
        desktopPane.setBackground(Color.LIGHT_GRAY);
        getContentPane().add(desktopPane, BorderLayout.CENTER);
        desktopPane.setLayout(null);

        JPanel panel = new JPanel();
        getContentPane().add(panel, BorderLayout.NORTH);

        JButton btnOpenInternalframe = new JButton("Open InternalFrame");
        btnOpenInternalframe.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JInternalFrame f = new JInternalFrame("Test", false, true, false);
                f.setBounds(250, 50, 300, 200);
                desktopPane.add(f);
                f.show();
            }
        });
        panel.add(btnOpenInternalframe);
        setBounds(100, 50, 700, 600);
        setVisible(true);
    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        new TestJInternalFrame();
    }
}
SlimenTN
  • 3,383
  • 7
  • 31
  • 78
  • You should include the code that generates the frame to help you find the problem. – Sebastian Oct 13 '15 at 12:22
  • There is no code just when I call JInternalFrame I get this design, nothing special. – SlimenTN Oct 13 '15 at 12:28
  • `There is no code just when I call JInternalFrame I get this design, nothing special` - then post your [SSCCE](http://sscce.org/) that demonstrates the problem. My internal frame does not look like that when I run the code from the Swing tutorial on [How to Use Internal Frames](http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html). Try that demo code to see if you have the same problem. – camickr Oct 13 '15 at 14:52
  • @camickr please take a look at the picture, my problem is not about the code it's about the design.The above internalFrame is from Java the socond one is from C# as you can see the close button in Java internal frame is miss placed.My question is : is it some kind of bad design or no ? – SlimenTN Oct 13 '15 at 15:13
  • @SlimenTunis, I already stated I do not have the same problem you do. So therefore the problem is your code or your JDK. A picture tells us nothing about the code you are using. Read my comment and look at the tutorial. You will see the button is placed correctly in the tutorial code. If you don't post the code you used, then we can't verify if the problem is your code or your platform. – camickr Oct 13 '15 at 15:19
  • @camickr let's make this clear in the nimbus and metal L&F there is no problem with the design but when you use windows L&F you will see this problem, and in the tutorial you gave me they are using default L&F so that's why you can't see the problem. – SlimenTN Oct 13 '15 at 15:30
  • `It's a simple code` - you were asked to post a `SCCE` The code you posted doesn't compile therefore I can't test the code to verify the problem. Good luck, I don't have any more time to spend repeating myself. – camickr Oct 13 '15 at 15:47
  • @camickr I posted a SCCE, please take a look. – SlimenTN Oct 13 '15 at 15:56
  • `Is it a design bug or something ?` - that would be my guess. The layout code can be found in "com\sun\java\swing\plaf\windows\WindowsInternalFrameTitlePane.java" class. In particular you might want to look the internal "WindowsTilePaneLayout" class. I don't know where the problem is or even know how to override the class even if I could find the problem. – camickr Oct 13 '15 at 18:27

0 Answers0