Setting background color for a JFrame
Retrieve the content pane for the frame and use the setBackground() method inherited from Component to change the color. Example:
Retrieve the content pane for the frame and use the setBackground() method inherited from Component to change the color. Example:
See the java doc for JTextField Sample code can be:
There is no specialized image component provided in Swing (which is sad in my opinion). So, there are a few options: As @Reimeus said: Use a JLabel with an icon. Create in the window builder a JPanel, that will represent the location of the image. Then add your own custom image component to the JPanel … Read more
DTO is an abbreviation for Data Transfer Object, so it is used to transfer the data between classes and modules of your application. DTO should only contain private fields for your data, getters, setters, and constructors. DTO is not recommended to add business logic methods to such classes, but it is OK to add some … Read more
addNotify() gets called whenever the Component gets added to a Container. This method can therefore be used to gain parent information without the risk of having a null parent, which in the constructor is more than likely. requestFocus() makes a request that the given Component gets set to a focused state. This method requires that … Read more
If you want the GUI to behave as if you clicked the X close button then you need to dispatch a window closing event to the Window. The ExitAction from Closing An Application allows you to add this functionality to a menu item or any component that uses Actions easily.
The complete Swing processing is done in a thread called EDT (Event Dispatching Thread). Therefore you would block the GUI if you would compute some long lasting calculations within this thread. The way to go here is to process your calculation within a different thread, so your GUI stays responsive. At the end you want … Read more
Assuming you are talking about the ActionEvent class, then there is a big difference between the two methods. getActionCommand() gives you a String representing the action command. The value is component specific; for a JButton you have the option to set the value with setActionCommand(String command) but for a JTextField if you don’t set this, … Read more
It’s worth reading here about Oracle Tutorial – Enabling Keyboard Operation where it is explained in details along with sample. Read more about on Oracle Tutorial – How to Use Key Bindings Some example directly from the above tutorial: Read more here Oracle Tutorial – How to Use Buttons, Check Boxes, and Radio Buttons Sample … Read more