JButton设置为true
时间: 2024-01-22 16:18:30 浏览: 27
JButton 的 setEnabled(boolean b) 方法可以用来设置按钮的启用状态。如果参数 b 为 true,则按钮处于启用状态,否则按钮处于禁用状态。例如,下面的代码将一个名为 button 的 JButton 设置为启用状态:
```
button.setEnabled(true);
```
这样用户就可以点击该按钮执行相应的操作了。
相关问题
JButton设置为fasle
如果你想要禁用 JButton,你可以调用 setEnabled(false) 方法。这将使按钮变为灰色并且无法接收用户的点击。代码示例:
```java
JButton button = new JButton("Click me");
button.setEnabled(false); // 禁用按钮
```
如果你想重新启用按钮,只需要调用 setEnabled(true) 方法即可。
jbutton设置边框为圆角矩形
您可以使用下面这段代码来设置JButton的边框为圆角矩形:
```
jbutton.setBorder(new RoundBorder(20));
```
其中,RoundBorder是自定义的一个类,代码如下:
```
import java.awt.*;
import java.awt.geom.*;
import javax.swing.border.*;
public class RoundBorder implements Border {
private int radius;
public RoundBorder(int radius) {
this.radius = radius;
}
public Insets getBorderInsets(Component c) {
return new Insets(this.radius + 1, this.radius + 1, this.radius + 2, this.radius);
}
public boolean isBorderOpaque() {
return true;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(c.getBackground());
g2.fill(new RoundRectangle2D.Double(x, y, width - 1, height - 1, radius, radius));
g2.setColor(c.getForeground());
g2.draw(new RoundRectangle2D.Double(x, y, width - 1, height - 1, radius, radius));
}
}
```
这样,您就可以把JButton的边框设置为圆角矩形了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)