使用またはその他のレイアウトを追加JButtons
し、使用とキーの間を移動したい..の行と列がわからないため、上下に移動するのに問題があります。JPanel
FlowLayout
JButtons
Up
Down
JButton
public class abc{
List<ControlCenterButton> buttons=getButtons();
JPanel buttonPanel= new JPanel();
buttonPanel.setLayout(new FlowLayout)
for (int i = 0; i < buttons.size(); i++) {
ControlCenterButton button = buttons.get(i);
if (button.getLayarID().equals(id)) {
flag = true;
button.addActionListener(this);
button.setPosition(i);
button.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent mouseEvent) {
buttonPanel.requestFocusInWindow();
}
});
buttonPanel.add(button);
}
buttonPanel.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent keyEvent) {
final ControlCenterButton selectedControlCenterButton = (ControlCenterButton) Session.getSession().getAttribute("controlcenter.selectedbutton");
int position = selectedControlCenterButton.getPosition();
int keycode = keyEvent.getKeyCode();
switch (keycode) {
case KeyEvent.VK_RIGHT: {
if (position + 1 >= buttons.size()) {
ControlCenterButton.selectButton(buttons.get(0));
} else
ControlCenterButton.selectButton(buttons.get(position + ));
break;
}
case KeyEvent.VK_UP: {
break;
}
case KeyEvent.VK_DOWN: {
}
case KeyEvent.VK_ENTER: {
selectedControlCenterButton.requestFocusInWindow();
new ControlCenterButton().openApplication(selectedControlCenterButton);
break;
}
}
}
public class ControlCenterButton extends JButton implements ActionListener {
private int position;
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}