JProgressBar:不会显示低值 [英] JProgressBar: low values will not be displayed

查看:129
本文介绍了JProgressBar:不会显示低值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中尝试了JProgressBar的功能。但是有一个问题我无法解决:

I tried out the function of the JProgressBar in Java. But there is a problem I couldn't solve:

当我将最小值设置为零时,最大值设置为100,当前值设置为6则不会显示任何内容。进度条为空。如果我把7作为当前值,那么它的工作原理。这似乎是任何空边框或其他空间的问题。 Windows 7出现此问题,并且仅当UIManager设置为SystemLookAndFeel时才会出现此问题。

When I set the minimum to zero, the maximum value to 100 and the current value to 6 then nothing will be displayed. The progress bar is empty. If I put 7 as current value then it works. It seems to be a problem with any empty border or other space. The problem occurs with Windows 7 and only if the UIManager is set to SystemLookAndFeel.

是否有人知道此问题并且有解决方案?以下是我的代码:

Does anyone knows this problem and has a solution for this? Below is my code:

package lab;

import java.awt.FlowLayout;

import javax.swing.JDialog;
import javax.swing.JProgressBar;
import javax.swing.UIManager;

import core.Config;


public class ProgressSample extends JDialog {

public ProgressSample() {

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    getContentPane().setLayout(new FlowLayout());

              // Nothing is displayed
    JProgressBar progressSix = new JProgressBar(0, 100);
    progressSix.setValue(6);
    getContentPane().add(progressSix);

              // This works
    JProgressBar progressSeven = new JProgressBar(0, 100);
    progressSeven.setValue(7);
    getContentPane().add(progressSeven);

    pack();
}

public static void main(String[] args) {

    try {
        UIManager.setLookAndFeel(UIManager
        .getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    ProgressSample dialogTest = new ProgressSample();
    dialogTest.setVisible(true);
}

}


推荐答案

Windows原生外观进度条的java代码使用原始窗口进度条的方式使用 PROGRESSCHUNKSIZE 进行渲染。请参阅 Windows JProgressBar的来源

The java code for a Windows native look-and-feel progress bar renders using PROGRESSCHUNKSIZE steps in the manner of the original windows progress bar. Please see the source for the Windows JProgressBar.

它只是没有顺利渲染它。如果你步进进度条,你可以看到块。

It's just not rendering it smoothly. If you step the progress bar you can see the chunks.

它可以自定义,但我不知道你将如何实现它。

It may be customizable, but I don't know how you would accomplish it.

问题的根源

最初的Windows XP进度条在小框中。 主题定义盒子的大小,以及盒子之间的空隙。对于Vista及更高版本,主题已更改为将框之间的间距指定为0,但从未将框的大小重置为1像素。通过 OpenThemeData GetThemeInt Win32API 函数读取值我的主题(Windows 8)的块大小 6

The original windows XP progress bar was in little boxes. The theme defined a size of the box, and the gap between the box. For Vista and later, the theme was changed to specify the gap between the box as 0, but never reset the size of the box to 1 pixel. Reading the value through the OpenThemeData and GetThemeInt Win32API functions reveals that the chunk size is 6 for my theme (Windows 8).

这篇关于JProgressBar:不会显示低值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆