【发布时间】:2015-01-25 10:52:57
【问题描述】:
提前感谢您的帮助。 我有这个代码来创建一个按钮:
frame1.getContentPane().add(new DragButton("Z"));
我添加了一个随机位置:
frame1.getContentPane().add(new DragButton("Z")).setLocation((int) Math.floor((Math.random() * 600) + 1),(int) Math.floor((Math.random() * 300) + 1));
但现在我想为按钮添加颜色。我知道我可以使用 .setBackground(Color.GREEN) 选项,但是在使用 .setLocation 选项之后或之前这样做,它给了我一个“不能尊重无效”的错误,我被困在这部分。我已经在这里看到了几篇帖子,但它们要么专注于位置部分,要么专注于颜色部分,而不是两者兼而有之。感谢您的帮助!!
【问题讨论】:
标签: java swing button colors position