Java 选中JToggleButton后,禁用其标准重新绘制
我希望我的JToggleButton在被选中时不要重新绘制。我用一对字(“检查/下一步”)表示状态改变。Java 选中JToggleButton后,禁用其标准重新绘制,java,swing,jtogglebutton,Java,Swing,Jtogglebutton,我希望我的JToggleButton在被选中时不要重新绘制。我用一对字(“检查/下一步”)表示状态改变。 标准行为是蓝色照明,但我想禁用它 也许您可以在图像图标上显示文字。例如: import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import
标准行为是蓝色照明,但我想禁用它 也许您可以在图像图标上显示文字。例如:
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
public class ToggleFun {
private static final Color BACKGROUND_COLOR = new Color(200, 200, 255);
public static void main(String[] args) {
int biWidth = 60;
int biHeight = 30;
BufferedImage checkImg = new BufferedImage(biWidth, biHeight, BufferedImage.TYPE_INT_RGB);
BufferedImage nextImg = new BufferedImage(biWidth, biHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = checkImg.createGraphics();
g2.setColor(BACKGROUND_COLOR);
g2.fillRect(0, 0, biWidth, biHeight);
g2.setColor(Color.black);
g2.drawString("Check", 10, 20);
g2.dispose();
g2 = nextImg.createGraphics();
g2.setColor(BACKGROUND_COLOR);
g2.fillRect(0, 0, biWidth, biHeight);
g2.setColor(Color.black);
g2.drawString("Next", 15, 20);
g2.dispose();
ImageIcon checkIcon = new ImageIcon(checkImg);
ImageIcon nextIcon = new ImageIcon(nextImg);
JToggleButton toggleBtn = new JToggleButton(checkIcon);
toggleBtn.setSelectedIcon(nextIcon);
toggleBtn.setContentAreaFilled(false);
toggleBtn.setBorder(BorderFactory.createLineBorder(Color.black));
JPanel panel = new JPanel();
panel.add(toggleBtn);
JOptionPane.showMessageDialog(null, panel);
}
}
也许您可以在图像图标上显示这些文字。例如:
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
public class ToggleFun {
private static final Color BACKGROUND_COLOR = new Color(200, 200, 255);
public static void main(String[] args) {
int biWidth = 60;
int biHeight = 30;
BufferedImage checkImg = new BufferedImage(biWidth, biHeight, BufferedImage.TYPE_INT_RGB);
BufferedImage nextImg = new BufferedImage(biWidth, biHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = checkImg.createGraphics();
g2.setColor(BACKGROUND_COLOR);
g2.fillRect(0, 0, biWidth, biHeight);
g2.setColor(Color.black);
g2.drawString("Check", 10, 20);
g2.dispose();
g2 = nextImg.createGraphics();
g2.setColor(BACKGROUND_COLOR);
g2.fillRect(0, 0, biWidth, biHeight);
g2.setColor(Color.black);
g2.drawString("Next", 15, 20);
g2.dispose();
ImageIcon checkIcon = new ImageIcon(checkImg);
ImageIcon nextIcon = new ImageIcon(nextImg);
JToggleButton toggleBtn = new JToggleButton(checkIcon);
toggleBtn.setSelectedIcon(nextIcon);
toggleBtn.setContentAreaFilled(false);
toggleBtn.setBorder(BorderFactory.createLineBorder(Color.black));
JPanel panel = new JPanel();
panel.add(toggleBtn);
JOptionPane.showMessageDialog(null, panel);
}
}
请参阅:
但请注意,用户通常更喜欢遵循“最少意外路径”的GUI元素。这种类型的渲染可以更好地描述为在路径旁边的灌木丛中突然发生碰撞。请参见:
但请注意,用户通常更喜欢遵循“最少意外路径”的GUI元素。这种类型的渲染可以更好地描述为在路径旁边的灌木丛中突然发生碰撞。也许您可以显示图像图标上的文字。切换按钮的“检查”和“下一步”有效替代选项是什么?我可以(几乎画出)“下一个/上一个”,“下一个/当前”,“检查/跳过”…也许你可以在图像图标上显示这些词。“检查”和“下一个”切换按钮的有效选项是什么?我可以(几乎画出)“下一个/上一个”,“下一个/当前”,“检查/跳过”…它完全禁用windows样式的图形,我的按钮看起来像标签。它完全禁用windows样式的图形,我的按钮看起来像标签。很好的技巧。我将在我的应用程序的另一部分中使用它。但实际上不是我想要的。当切换按钮被选中时,有轻微的蓝色灯光,我想禁用它,但不禁用Windows操作系统的按钮样式。很好的技巧。我将在我的应用程序的另一部分中使用它。但实际上不是我想要的。当选择“切换按钮”时,会有轻微的蓝色灯光,我想禁用它,但不禁用Windows OS按钮样式。