Jtextarea граница в Java SwingJAVA

Программисты JAVA общаются здесь
Anonymous
Jtextarea граница в Java Swing

Сообщение Anonymous »

Я новичок в Java и создаю виджеты пользовательского интерфейса с использованием Java и создал следующий класс для того же. Но для того, чтобы добавить границу в Textarea, я знаю, что я должен использовать класс BorderFactory. Но так как у меня есть отдельный класс для JFrame и JTextArea, я не мог этого сделать. Есть помощь? < /P>

class < /p>

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;
}

}
< /code>

и моя основная программа < /p>

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);
}
}


Подробнее здесь: https://stackoverflow.com/questions/426 ... java-swing

Вернуться в «JAVA»