简体   繁体   中英

How to make JFrame INVISIBLE with a JPanel that is VISIBLE?

I'm sorry for using caps, my last attempt of asking this question wasn't clear which is fine. How do I make the JFrame fully invisible, not: '.setUndecorated(true)', but actually invisible and put a JPanel on that JFrame that is visible. So pretty much, the JPanel will act as a JFrame, but I need the JFrame to be bigger than the JPanel because I'd like to add shadow around the JPanel, which has been figured out already.

Just make the frame background transparent:

JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setBackground(new Color(1.0f, 1.0f, 1.0f, 0.5f));

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 400);
frame.setLocationRelativeTo(null);

JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("Top", SwingConstants.CENTER), BorderLayout.NORTH);
panel.add(new JLabel("Bottom", SwingConstants.CENTER), BorderLayout.SOUTH);
panel.add(new JLabel("Right", SwingConstants.CENTER), BorderLayout.EAST);
panel.add(new JLabel("Left", SwingConstants.CENTER), BorderLayout.WEST);

frame.setLayout(new BorderLayout());
frame.add(panel, BorderLayout.CENTER);

frame.setVisible(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM