1
我有以下兩類:jbutton.setEnabled(假)不會禁用按鈕輸入
#1
public class LobbyView extends JPanel
{
private final JButton sendGameRequestButton = new JButton();
public JButton getSendGameRequestButton()
{
return sendGameRequestButton;
}
LobbyView()
{
sendGameRequestButton.setPreferredSize(new Dimension(15, 20));
sendGameRequestButton.setText("Send game request");
sendGameRequestButton.addMouseListener(new LobbyListener(this));
sendGameRequestButton.setEnabled(false);
}
}
#2
public class LobbyListener implements MouseListener
{
LobbyView lobbyView;
public LobbyListener(LobbyView sentLobbyView)
{
lobbyView = sentLobbyView;
}
@Override
public void mouseClicked(MouseEvent e)
{
if (e.getButton() == 1)
{
if (e.getSource() == lobbyView.getSendGameRequestButton())
{
System.out.println("You pushed the disabled button");
}
}
}
即使我在LobbyView構造函數中禁用了JButton,我仍然可以點擊它並獲取消息「You pushe d禁用按鈕「。
是否component.setEnabled(false)實際上DISABLE一個組件,或只是灰色,使它看起來被禁用?
+1。他也不應該設置首選大小。 –