Я пытаюсь добавить горизонтальную и вертикальную полосу прокрутки, чтобы прочитать весь текстовый файл после его открытия.Потому что, как у меня это структурировано, файл отображается только частично.Пожалуйста, смотрите изображение ниже и код.Есть ли что-то, что я делаю неправильно?Обновленный код
public class OpenFile {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
OpenFile window = new OpenFile();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public OpenFile() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.getContentPane().setLayout(null);
JTextArea jTextArea1 = new JTextArea();
jTextArea1.setBounds(15, 45, 398, 183);
//frame.getContentPane().add(new JScrollPane(jTextArea1));
JButton btnNewButton = new JButton("Read Text");
frame.getContentPane().add(btnNewButton, BorderLayout.SOUTH);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
String nameFile = f.getAbsolutePath();
try {
FileReader reader = new FileReader(nameFile);
BufferedReader br = new BufferedReader(reader);
jTextArea1.read(br, null);
br.close();
jTextArea1.requestFocus();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
});
btnNewButton.setBounds(15, 16, 115, 29);
frame.getContentPane().add(btnNewButton);
}
}
Понятия не имею, почему он отображается так, как показано на рисунке.Пожалуйста, сообщите.