文字区域超过窗口区域

问题描述

我已经用Java编写了程序,程序是将KM转换为英里,将英里转换为KM,程序运行正常,但问题是文本区域超出了该区域,因此在附加的代码下未显示全文。所以我想如果在行尾到达它会转到新行

Message: Global HTTP Batch endpoint is deprecated. See https://g.co/cloud/global-batch-deprecation for info and migration steps.

解决方法

如果您的目标仅仅是在文本区域中换行,则可以使用 JTextArea的内置函数 setLineWrap

将真实的布尔值作为参数传递给 setLineWrap (例如 setLineWrap(true))将打开JTextArea组件的换行。传递错误的布尔值作为参数将关闭自动换行

在您的代码中,其用法如下。

output.setLineWrap(true);

转换器构造函数如下所示。

    public Converter() {
    
    // Turn on line wrapping.
    output.setLineWrap(true);
    
    setLayout(null);
    setSize(300,400);
    // left-down-width-hegiht
    cb1.setBounds(60,30,150,30);
    cb2.setBounds(60,60,30);
    label.setBounds(30,90,120,30);
    input.setBounds(90,95,170,20);
    button.setBounds(100,130,30);
    output.setBounds(45,168,200,165);
    add(cb1);
    add(cb2);
    add(label);
    add(input);
    add(button);
    add(output);
    button.addActionListener(this);
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...