java jtextarea边框_JTextArea在java swing中的边框

我是

java新手并使用

java创建UI小部件并为此创建了以下类.但是为了向textarea添加边框,我知道我必须使用borderfactory类.但是因为我有JFrame和JTextArea的单独类,所以我无法做到.有帮助吗?

import javax.swing.*;

import java.awt.*;

import javax.swing.BorderFactory;

public class UIFactory {

//Border border = BorderFactory.createLineBorder(Color.BLACK);

public JButton newButton(int posx, int posy, int buttonWidth, int buttonHeight) {

JButton b = new JButton("Test");

b.setBounds(posx, posy, buttonWidth, buttonHeight);

return b;

}

public JFrame newFrame(int width, int height) {

JFrame f = new JFrame();

f.setSize(width, height);

f.setLayout(null);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

return f;

}

public JTextArea newTextArea(int xpos, int ypos, int twidth, int theight) {

JTextArea t = new JTextArea(300,300);

JScrollPane sp = new JScrollPane(t);

t.setBounds(xpos, ypos, twidth, theight);

t.setBackground(Color.orange);

t.setForeground(Color.black);

// t.setBorder(BorderFactory.createCompoundBorder(border,BorderFactory.createEmptyBorder(10, 10, 10, 10)));

return t;

}

}

和我的主要计划

import javax.swing.*;

import java.awt.*;

public class MyUI {

public static void main(String[] args) {

UIFactory ui = new UIFactory();

JFrame mainf = ui.newFrame(800, 800);

mainf.setLocation(400, 400);

JButton b2;

JButton b3;

mainf.add(b2 = ui.newButton(50, 50, 100, 50));

mainf.add(b3 = ui.newButton(50, 100, 100, 50));

JTextArea area;

mainf.add(area = ui.newTextArea(170,50,1600,300));

mainf.setVisible(true);

mainf.add(area = ui.newTextArea(170,400,1600,300));

mainf.setVisible(true);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值