下面列出了javax.swing.JToggleButton#setContentAreaFilled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void updateState() {
JEditorPane pane = getPane();
if (pane != null) {
boolean rectangleSelection = RectangularSelectionUtils.isRectangularSelection(pane);
JToggleButton toggleButton = getToggleButton();
if (toggleButton != null) {
toggleButton.setSelected(rectangleSelection);
toggleButton.setContentAreaFilled(rectangleSelection);
toggleButton.setBorderPainted(rectangleSelection);
}
}
}
private JToggleButton createCell() {
JToggleButton newCell = new JToggleButton();
newCell.addMouseListener(mouseListener);
newCell.addMouseMotionListener(mouseListener);
newCell.setContentAreaFilled(false);
newCell.setBorder(null);
newCell.setRequestFocusEnabled(false);
newCell.setBorderPainted(false);
newCell.setOpaque(false);
newCell.putClientProperty(PROPERTY_CELL, Boolean.TRUE);
newCell.addActionListener(cellActionListener);
return newCell;
}
private void initGUI()
{
// 实例化按钮
ButtonGroup bg = new ButtonGroup();
btnLeft = new JToggleButton("");
btnRight = new JToggleButton("");
btnLeft.setContentAreaFilled(false);
btnLeft.setFocusable(false);
btnLeft.setBorder(null);
btnLeft.setPreferredSize(new Dimension(64,25));
btnRight.setContentAreaFilled(false);
btnRight.setFocusable(false);
btnRight.setBorder(null);
btnRight.setPreferredSize(new Dimension(64,25));
// 加入到ButtonGroup(实现RadioButton的形为)
bg.add(btnLeft);
bg.add(btnRight);
// 主面板布局
FlowLayout mainLayout = new FlowLayout(FlowLayout.CENTER);
mainLayout.setHgap(0);
mainLayout.setVgap(2);
this.setLayout(mainLayout);
// 此处的border的设置是为了背景上部的装饰而做哦
this.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
// 实例化按钮面板
btnPane = new BtnPane();
btnPane.add(btnLeft);
btnPane.add(btnRight);
// 添加到总体布局中
this.add(btnPane);
}