简体   繁体   English

如何以代号制作圆形进度条?

[英]How to make a round Progress Bar in codename one?

I want to create a round progress bar, depicting the current status in percent in its mid. 我想创建一个圆形进度条,以中间的百分比描绘当前状态。 like this: 像这样:

圆形前卫吧

now I already followed the instructions on creating a flat progress bar , but as I am not familiar with swing and I don't have any clue of Javas graphics, I have no clue how to transfer from the 'flat' to the 'round' progress bar. 现在我已经按照创建平面进度条的说明 ,但由于我不熟悉swing并且我没有任何关于Javas图形的线索,我不知道如何从'flat'转换到'round'进度条。

How could a code similiar to the progress bar look like? 与进度条类似的代码怎么样?

ps: I saw Hannahs post on the analog clock and tried it like this - but failed due to my lack in painting (and maybe mathematical) skills. ps:我看到Hannahs在模拟时钟上发帖并试着这样 - 但由于我缺乏绘画(也许是数学)技能而失败了。

pps: I don't use the GUIBuilder at all (bare bones) pps: 我根本不使用GUIBuilder (裸骨)

ppps: I want it to be drawn (if possible), not image-based ppps:我希望它被绘制(如果可能的话),而不是基于图像的

I haven't tested it but something like this should work: 我没有测试它,但这样的东西应该工作:

Container progress = new Container(new LayeredLayout());
Label percent = new Label("0%");
percent.getUnselectedStyle().setAlignment(Component.CENTER);
progress.add(new Label(progressOverlayImage, "Container")).
        add(FlowLayout.encloseCenterMiddle(percent));
progress.getUnselectedStyle().setBgPainter((Graphics g, Rectangle rect) -> {
    g.setColor(0xff0000);
    g.fillArc(progress.getX(), progress.getY(), progressOverlayImage.getWidth(), progressOverlayImage.getHeight(), 0, currentProgress360);
});

You will need the following to get this to work. 您需要以下内容才能使其正常运行。

  • You will need to update the percentage label when changing the progress value 更改进度值时,您需要更新百分比标签
  • You will need an "overlay image" that is transparent where you want the progress to appear 您需要一个透明的“叠加图像”,以便显示进度
  • You will need a variable called currentProgress360 that will represent the current state of progress between 0 and 360 您将需要一个名为currentProgress360的变量,它将表示0到360之间当前的进度状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM