在Swing(也是AWT)中,int secondsDelayed = 1;
new Handler().postDelayed(new Runnable() {
public void run() {
startActivity(new Intent(LoginSuccessFull.this, LoginActivity.class));
finish();
}
}, secondsDelayed * 1500);
确定LayoutManager
内Component
s的大小和位置,而不绘制边和线......
对于某些教育目标,如何绘制这些行?(例如,覆盖Container
类的paintComponents()
等等......)
解决方案是根据每个布局的规则计算所有内容以获取坐标,但有没有办法使用布局本身来做到这一点?
答案 0 :(得分:2)
如果您希望所有组件都有边框,则可以使用循环。以下方法将为JComponent
内容窗格中的所有 Swing 组件(实际上为JFrame
s)绘制边框:
Container cont = frame.getContentPane();
Component[] components = cont.getComponents();
List<JComponent> list = new ArrayList<>();
for (Component comp : components) {
if (comp instanceof JComponent) {
list.add((JComponent) comp);
}
}
for (JComponent jComponent : list) {
jComponent.setBorder(BorderFactory.createLineBorder(Color.black,2));
}
这就是你得到的(忽略菜单栏,它来自上一个问题):