I have a small GUI contains JPanel in which have got JTextArea and JLabel, when I make
panel1.setLayout(null);
I can get the required position done but JTextArea disappearing! when I make
panel1.setLayout((LayoutManager) new FlowLayout(FlowLayout.LEFT));
I can get both Jlabel and JTextArea visible but couldn't able to get the position, How to get the required position set, am newbie! help please! thanks
Code:
private void createPageScreen1() {
panel1 = new JPanel();
panel1.setLayout((LayoutManager) new FlowLayout(FlowLayout.LEFT));
//panel1.setLayout(null);
//panel1.setLayout(new BorderLayout());
JLabel lblProcessingData = new JLabel();
//lblProcessingData.setBounds(5, 5, 15, 10);
lblProcessingData.setLocation(5, 5);
lblProcessingData.setText("label for Title");
panel1.add(lblProcessingData);
String fileName = "loadFiles\\testFile.txt";
try {
textArea = new JTextArea(40, 37);
//textArea.setBounds(5, 20, 40, 37);
textArea.setBorder (new TitledBorder (new EtchedBorder(), fileName));
textArea.setLineWrap(true);
textArea.setEditable(false);
textArea.setVisible(true);
FileReader reader = new FileReader(fileName);
BufferedReader br = new BufferedReader(reader);
textArea.read(br, null);
br.close();
textArea.requestFocus();
JScrollPane scroll1 = new JScrollPane(textArea);
scroll1.setVerticalScrollBarPolicy (ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel1.add(scroll1);
} catch (Exception e) {
e.printStackTrace();
}
panel1.setVisible(true);
}
Aucun commentaire:
Enregistrer un commentaire