JButton.setBounds(x,y,w,h) doesn't seem to work

前端 未结 2 1111
借酒劲吻你
借酒劲吻你 2021-01-20 14:56
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class SimpleExample extends JFrame {

    public SimpleExample() {
         


        
相关标签:
2条回答
  • 2021-01-20 15:14

    As a good practice, you should not add the button directly to the JFrame. Instead, add a JPanel to the frame, set the panel's layout to null, and add the JButton to the JPanel.

    0 讨论(0)
  • 2021-01-20 15:17

    Your frame is under the control of a layout manager, it is making the decisions on how best to layout your components and is overriding the values you have specified using setBounds

    Modern GUIs need to run (even on the same OS) in a variety of different graphical environments, including different DPI, screen sizes and font settings for example.

    The layout manager makes it possible for you to worry (less) about these issues and it is highly recommended that you make use of them

    Take a look at

    • Using Layout Managers
    • A Visual Guide to Layout Managers

    For more details

    0 讨论(0)
提交回复
热议问题