小编Leb*_*ski的帖子

Java GridBagLayout不会水平填充框架

我正在为聊天程序编写GUI.我似乎无法scroller水平和垂直messageInput地填充框架并且水平地填充框架.这是它的样子:

在此输入图像描述

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

public class GUI extends JFrame{

private JPanel panel;
private JEditorPane content;
private JTextField messageInput;
private JScrollPane scroller;
private JMenu options;
private JMenuBar mb;
private JMenuItem item;

public GUI(){
    /** This is the frame**/
    this.setPreferredSize(new Dimension(380,600));
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;

    /** This is where the context shows up **/
    content = new JEditorPane();
    content.setEditable(false);

    /** Scroller that shows up in the …
Run Code Online (Sandbox Code Playgroud)

java swing layout-manager gridbaglayout

4
推荐指数
1
解决办法
3161
查看次数

标签 统计

gridbaglayout ×1

java ×1

layout-manager ×1

swing ×1