简体   繁体   English

JTextArea不允许输入文本

[英]JTextArea won't allow for text to be typed in

I've read up on the other questions about JTextArea and moved the setVisible(true) to the bottom, but my JTextArea still will not let me display text. 我已经阅读了有关JTextArea的其他问题,并将setVisible(true)移到底部,但是我的JTextArea仍然不允许我显示文本。 My code is below, it is the constructor of a class that extends JPanel, it won't show anything when I type into the JTextArea. 我的代码在下面,它是扩展JPanel的类的构造函数,当我键入JTextArea时不会显示任何内容。 The JTextArea appears in the middle, called "newText." JTextArea出现在中间,称为“ newText”。 Thank you for your help! 谢谢您的帮助!

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

Ok somebody answered my question and then deleted that response so I will post it here, this was not my doing but it was the problem with the program and so here it is! 好的,有人回答了我的问题,然后删除了该答复,所以我将其张贴在这里,这不是我的工作,但这是程序的问题,所以这里是!

setLayout(new BorderLayout(500,500)); setLayout(new BorderLayout(500,500)); puts large gaps on that cover the whole are. 在整个覆盖范围上存在很大的差距。

Solution: reduce the gaps 解决方案:缩小差距

setLayout(new BorderLayout(5,5)); setLayout(new BorderLayout(5,5));

Code Riddle: Completed. 代码谜语:已完成。 Thank you Everyone! 谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM