![]() The program looks like this: You can download source code of this program in the attachment section. JButton demo programFor reference, we created a demo program which incorporates all the practices mentioned above. Change font style, background color and foreground color of the button:ītFont(new ("Arial", Font.BOLD, 14)) ītText("Edit") 7.Here is the code to set the button as default button in the frame window: getRootPane().setDefaultButton(button) The default button is bold in the window like the 3 rd button in this screenshot: 6. Setting a JButton as the default buttonA window can have a default button whose action will be invoked when the user hits Enter key. Adding an event listener using anonymous class (shortcut way):īutton.addActionListener(new ActionListener() void actionPerformed(ActionEvent evt) ) 5. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |