I have a JFrame and an ImageIcon as a JLabel that I want to appear fully off of the JFrame.
Code:
JFrame frame = new JFrame("test");
frame.setSize(1000, 1000);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
BufferedImage bf = ImageIO.read(new File(FILEPATH));
img = new JLabel(new ImageIcon(bf));
} catch (IOException e) {
e.printStackTrace();
}
frame.getContentPane().add(img);
img.setBorder(new EmptyBorder(0, frame.getContentPane().getWidth(), 0, 0));
This code only makes the JLabel/image appear half off of the screen. I can easily fix it by setting the left parameter of the EmptyBorder
to frame.getContentPane.getWidth() * 2
, but I am just wondering why it seems to cut the inset distance in half. From my testing, only cuts it in half if the JLabel contains an ImageIcon. If it contains text, the insets work as they seem like they should. I have only tested with text and ImageIcon.