JButton() only working when mouse hovers

后端 未结 4 1444
不知归路
不知归路 2020-11-27 08:26
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import javax.imageio.*;
    import java.lang.*;
    import java.io.*;
    import         


        
4条回答
  •  野性不改
    2020-11-27 08:27

    Likely you have a layout problem where you're trying to add JButtons with absolute bounds into a container that uses a non-null layout manager. Suggestions

    • Do not use setBounds and absolute positioning to size and place your components.
    • Read up on and use the layout managers to do this heavy lifting for you: Lesson: Laying Out Components Within a Container
    • Don't forget to call pack() on your JFrame after adding all components
    • Call setVisible(true) after calling pack() and again call both only after adding all components to your GUI.
    • A null layout is available if you absolutely need to use absolute positioning of components, but regardless, you should strive to avoid using it.

提交回复
热议问题