I have a JButton
which generates a JPanel
that contains a set of JLabel
components. As you can see, the amount of labels can be a bit too much for 600x600 frame to hold. I tried adding JScrollPane
, but nothing works for some reason. Changing layout manager to something other than null
and adding scroll pane completely breaks the panel and frame just appears completely blank.
createTable.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
ReadFile file = new ReadFile(path);
String[] aryLines = file.OpenFile();
JFrame frame2 = new JFrame("Table");
JPanel panel = new JPanel();
// JScrollPane scrollPane = new JScrollPane(panel);
frame2.setSize(600, 300);
panel.setBounds(0, 0, 600, 600);
panel.setLayout(null);
//scrollPane.setPreferredSize(new Dimension(600,300));
for (counter = aryLines.length; counter > 0; counter-=6) {
JLabel jLabel1 = new JLabel("Имя: "+ aryLines[counter-6]);
JLabel jLabel2 = new JLabel("Деталь: " +aryLines[counter-5]);
JLabel jLabel3 = new JLabel("Дата прибытия заказа: " + aryLines[counter-3]);
JLabel jLabel4 = new JLabel("Дата заказа детали: " + aryLines[counter-4]);
JCheckBox jCheckBox = new JCheckBox();
JTextArea area = new JTextArea(Integer.toString(counter));
jLabel1.setBounds(15, 5 + (counter - 6)*30, 300, 20);
jLabel2.setBounds(15,35 + (counter - 6)*30, 300, 20);
jLabel3.setBounds(15, 70 + (counter - 6)*30, 300, 20);
jLabel4.setBounds(15, 100 + (counter - 6)*30,300,20);
//jLabel.setBackground(Color.BLACK);
panel.add(jLabel1); panel.add(jLabel2); panel.add(jLabel3); panel.add(jLabel4);
//panel.add(jCheckBox);
}
// scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
// frame2.getContentPane().add(scrollPane);
frame2.add(panel);
//panel.add(scrollPane);
frame2.setLayout(null);
frame2.setVisible(true);
} catch (IOException et){System.out.println("Error in CreateTable doc parser");}
}
});