Q:

How can I center a component in a JScrollPane?

Here's my code, I would like to center the JTextPane in the JScrollPane:
    JFrame frame = new JFrame("Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JTextPane editor = new JTextPane();
    editor.setEditorKit(this);
    JScrollPane scroll = new JScrollPane(editor);
    //scroll.setAlignmentX(JScrollPane.CENTER_ALIGNMENT); <<<didnt change anything, so //'ed it

    frame.getContentPane().add(scroll);

    frame.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());

A:

The problem might be the layout of you frame  first of all you have to set size for the frame and set alignment

