gpt4 book ai didi

java - 我如何对齐特定行中的所有 JProgressbar 显示它看起来像目标中所示

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:56:39 24 4
gpt4 key购买 nike

我有 10 个 JProgressbar,我试图将它们全部放在同一条直线上,以便它看起来像在目标中显示的那样,但是当我按照它运行时,它会如失败部分所示运行。

enter image description here

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import javax.swing.*;

public class YumYumYum {

private static JFrame f = new JFrame();
private static JPanel panelFirst;

public JProgressBar createJP(int input) {
JProgressBar jp = new JProgressBar(JProgressBar.VERTICAL);
jp.setPreferredSize(new Dimension(10, input));
return jp;
}

public YumYumYum() {
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setLayout(new FlowLayout());
f.setSize(320, 240);
f.setLocationRelativeTo(null);

// Main Menu
panelFirst = new JPanel();
panelFirst.setBackground(Color.BLACK);
panelFirst.setLayout(new FlowLayout(FlowLayout.LEFT, 5,30));
panelFirst.setVisible(true);

panelFirst.add(createJP(10));
panelFirst.add(createJP(20));
panelFirst.add(createJP(30));
panelFirst.add(createJP(40));
panelFirst.add(createJP(50));
panelFirst.add(createJP(60));
panelFirst.add(createJP(70));
panelFirst.add(createJP(80));
panelFirst.add(createJP(90));
panelFirst.add(createJP(100));

f.getContentPane().add(panelFirst);
f.pack();
f.setVisible(true);

}

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
YumYumYum s = new YumYumYum();
}
});
}

}

最佳答案

  public JProgressBar createJP(int input) {
JProgressBar jp = new JProgressBar(JProgressBar.VERTICAL, 0, 100);
//jp.setPreferredSize(new Dimension(10, 100));
//Why do you use PreferedSize if you want the size to be fixed?
jp.setSize(new Dimension(10, 100));
jp.setValue(input);
jp.setBackground(Color.BLACK);
setBorderPainted(false);
return jp;
}

关于java - 我如何对齐特定行中的所有 JProgressbar 显示它看起来像目标中所示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11540544/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com