布局在Windows 7中解体,但在Windows XP上看起来很好

时间:2011-05-16 07:54:37

标签: java jvm

我对Java的问题很奇怪,我的应用程序在Windows XP上看起来很好,但它在Windows 7上看起来很奇怪(布局刚刚解体)。有没有人有同样的问题? TextFields大小不同。

GroupLayout gl_panel = new GroupLayout(this);
        gl_panel.setHorizontalGroup(
                gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(gl_panel.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblPulseFrequency, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblChannelDelay_4, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                        .addComponent(lblChannelDelay, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                        .addComponent(lblChannelDelay_1, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                        .addComponent(lblChannelDelay_2, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                        .addComponent(lblChannelDelay_3, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                        .addComponent(lblBlankingTime, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(pulseFreqTextField, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                        .addComponent(blankingTimeTextField, 0, 0, Short.MAX_VALUE)
                        .addComponent(textField_9)
                        .addComponent(textField_8)
                        .addComponent(textField_7)
                        .addComponent(textField_6)
                        .addComponent(textField_5, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(gl_panel.createSequentialGroup()
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblus_3)
                                .addComponent(lblus_2)
                                .addComponent(lblus_1)
                                .addComponent(lblus)
                                .addComponent(lblus_4))
                            .addGap(18, 18, 18)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblChannelDelay_5, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                                .addComponent(lblChannelDelay_6)
                                .addComponent(lblChannelDelay_7, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                                .addComponent(lblChannelDelay_8, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                                .addComponent(lblChannelDelay_9, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(textField_14)
                                .addComponent(textField_13)
                                .addComponent(textField_12)
                                .addComponent(textField_11)
                                .addComponent(textField_10, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(lblus_6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(lblus_5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(lblus_7, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblus_8, javax.swing.GroupLayout.Alignment.LEADING))
                                .addComponent(lblus_9))
                            .addGap(230, 230, 230))
                        .addGroup(gl_panel.createSequentialGroup()
                            .addComponent(lblkhz)
                            .addContainerGap())))
            );
            gl_panel.setVerticalGroup(
                gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(gl_panel.createSequentialGroup()
                    .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(gl_panel.createSequentialGroup()
                            .addGap(117, 117, 117)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblChannelDelay)
                                .addComponent(textField_5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblus)
                                .addComponent(lblChannelDelay_5)
                                .addComponent(textField_10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblus_5, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblChannelDelay_1)
                                .addComponent(textField_6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblus_1)
                                .addComponent(lblChannelDelay_6)
                                .addComponent(textField_11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblus_6))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblChannelDelay_2)
                                .addComponent(textField_7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblus_2)
                                .addComponent(lblChannelDelay_7, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(textField_12, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblus_7))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblChannelDelay_3)
                                .addComponent(textField_8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblus_3)
                                .addComponent(lblChannelDelay_8)
                                .addComponent(textField_13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblus_8))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblChannelDelay_4)
                                    .addComponent(textField_9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblus_4)
                                    .addComponent(lblChannelDelay_9)
                                    .addComponent(textField_14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblus_9))))
                        .addGroup(gl_panel.createSequentialGroup()
                            .addGap(42, 42, 42)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblPulseFrequency)
                                .addComponent(pulseFreqTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblkhz))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(gl_panel.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblBlankingTime)
                                .addComponent(blankingTimeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addContainerGap(35, Short.MAX_VALUE))
            );

1 个答案:

答案 0 :(得分:1)

你尝试过不同的屏幕分辨率吗?即使两台机器具有相似的分辨率,XP和7也会以不同方式绘制边距,标题栏等,这会影响有效的帧尺寸,因此Java布局的行为可能会有所不同,具体取决于操作系统。如果您实际更改屏幕分辨率,布局可能会完全爆炸。

您的代码看起来像是由某些GUI构建器(如NetBeans Matisse)生成的。我很遗憾地说,但他们真的很糟糕。他们给你WYSIWYG印象,但他们只是不是所见即所得。考虑使用一些好的布局管理器(例如MIGLayout

)手动编写GUI