0

What I have: there are names of fonts on my computer (fontMassive.getFont[]);
What I need: Scrollable list of JLabel components named by these fonts;

Java shows to me one String without scroll;
I tried to replace FlowLayout with BorderLayout so that JScrollPane would understand that I need scroll, but the scroll pane just disappeared.

What am I doing wrong?

import javax.swing.*;
import java.awt.*;

public class Window extends JFrame {
    public  Window() {

        JPanel mainPanel = new JPanel();
        JPanel secondaryPanel = new JPanel();
        ArrayOfFonts fontMassive = new ArrayOfFonts();
       //Font font = new Font("Sitka Banner",Font.PLAIN, 14);
        JScrollPane scroll = new JScrollPane();

        setBounds(100,100,600,600);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setTitle("FontView");

        setLayout( new FlowLayout());


        JLabel[] jLabels = new JLabel[fontMassive.getLength()];
        for (int i = 0; i < fontMassive.getLength(); i++) {
            jLabels[i] = new JLabel(fontMassive.getFont(i));
            jLabels[i].setFont(new Font(fontMassive.getFont(i),Font.PLAIN, 14));;
            secondaryPanel.add(jLabels[i]);
        }
        secondaryPanel.setLayout(new FlowLayout());
        scroll.setViewportView(secondaryPanel);
        mainPanel.add(scroll);
        setContentPane(mainPanel);
        setVisible(true);
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

0 Answers0