JLabel won't show with JPanel.setLayout(null). Why?

我的梦境 提交于 2019-11-28 14:21:08

This is the problem with absolute positioning (or null layout). It requires you to set the sizes of all your components, otherwise they will stay are their default zero-size and won't appear. That's why it's always better to use a layout manager.

You have to set the size of the label explicitly; try using setBounds instead of setLocation. For example, lab.setBounds(100,100,200,30); Also there's no need to call setVisible(true); on the label.

Unless there's a very good reason to use a null layout and you know exactly what you're doing, using a layout manager is always where you should start.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!