0

I wish to center my scrollpane inside a Jframe but i cant seem to do it. I used the GUI builder in netbeans but i have edited the Alignment part to CENTER or Trailer, doesnt seem to do anything. I tried using the JScrollPane.setAlignment(CENTER) inside initcomponents but no luck there either.

layout.setHorizontalGroup(

        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(
                        layout.createSequentialGroup()
                                .addGap(40, 40, 40)
                                .addGroup(
                                        layout.createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)                              


                                                .addGroup(
                                                        layout.createSequentialGroup()
                                                                .addComponent(
                                                                        myScrollPane,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        760,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
4

1 回答 1

1

不要使用 IDE 来创建你的 GUI。了解如何创建 GUI 并自己编写代码。这样你就可以学习 Java 而不是 IDE。

使组件居中的最简单方法是使用 GridBagLayout:

frame.setLayout( new GridBagLayout() );
frame.add(scrollPane, new GridBagConstraints());
于 2014-04-09T15:28:47.837 回答