我已经阅读了有关JTextArea的其他问题并将setVisible(true)移到了底部,但我的JTextArea仍然不允许我显示文本。我的代码如下,它是扩展JPanel的类的构造函数,当我输入JTextArea时它不会显示任何内容。 JTextArea出现在中间,称为“newText”。谢谢你的帮助!
EditScreen(TaskMaster taskMaster, Task toEdit){
this.taskMaster = taskMaster;
editingTask = toEdit;
textAreaShading = new Color(10, 20, 20, 20);
initBackground();
this.setLayout(new BorderLayout(500,500));
this.setBackground(background); //this might not be initializedset
topToolbar = new JPanel();
topToolbar.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
topToolbar.setOpaque(false);
topToolbar.setLayout(new BoxLayout(topToolbar, BoxLayout.X_AXIS));
category = new JLabel("Choose type:");
categories = new JComboBox(catS);
date = new JTextField(10);
topToolbar.add(category);
topToolbar.add(categories);
topToolbar.add(new JLabel("Due Date:"));
topToolbar.add(date);
textPanel = new JPanel();
//textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
textPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
textPanel.setLayout(new BorderLayout());
//textPanel.setOpaque(false);
textPanel.setBackground(Color.CYAN);
newText = new JTextArea();
newText.setOpaque(true);
newText.setBackground(textAreaShading);
newText.setLineWrap(true);
newText.setWrapStyleWord(true);
textPanel.add(BorderLayout.CENTER, newText);
bottomPanel = new JPanel();
bottomPanel.setBorder(BorderFactory.createEmptyBorder(5,5,2,0));
bottomPanel.setOpaque(false);
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
priority = new JComboBox(priorityS);
cancel = new JButton("Cancel");
save = new JButton("Save");
bottomPanel.add(new JLabel("Choose Priority:"));
bottomPanel.add(priority);
bottomPanel.add(cancel);
bottomPanel.add(save);
//set layout and size of frame
this.add(topToolbar,BorderLayout.NORTH);
this.add(textPanel, BorderLayout.CENTER);
//screenPanel.add(newText, BorderLayout.CENTER);
this.add(bottomPanel, BorderLayout.SOUTH);
initListeners();
initEditingTask();
this.setVisible(true);
textPanel.setVisible(true);
newText.setVisible(true);
}
答案 0 :(得分:0)
好的,有人回答了我的问题,然后删除了这个回复,所以我会在这里发布,这不是我的做法,但这是程序的问题,所以在这里!
setLayout(new BorderLayout(500,500));在这个封面上留下了很大的空白。
解决方案:缩小差距
setLayout(new BorderLayout(5,5));
Code Riddle:已完成。谢谢大家!