Why this code's JTextArea occupies entire JFrame?

后端 未结 2 954
梦如初夏
梦如初夏 2021-01-23 05:15

I expect part of my frame contains the JTextArea but it occupies entirely. I cannot trace the error here.

import java.awt.*;    
import javax.swing.*;

public cl         


        
相关标签:
2条回答
  • 2021-01-23 05:54

    You can try using Absolute layout. It's on the Layouts Pallet.

    Or enable it with :

    frame = new JFrame();
    ... //your code here
    
    // to set absolute layout.
    frame.getContentPane().setLayout(null);
    

    This way, you can freely place the control anywhere you like.

    0 讨论(0)
  • 2021-01-23 05:59

    JFrame by default uses BorderLayout. When you just add something onto a BorderLayout component like JFrame, it would add to the very center of the BorderLayout (if you did not specify where to add the component), and it takes up the entire JFrame.

    You should use the correct layout to adjust them.

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