下面列出了javax.swing.JProgressBar#setBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Create the frame.
*/
public SendFileFrame()
{
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 510, 196);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
lbl = new JLabel("进度条");
lbl.setBounds(42, 35, 74, 33);
contentPane.add(lbl);
progressBar = new JProgressBar();
progressBar.setForeground(Color.BLUE);
progressBar.setBounds(96, 35, 332, 33);
contentPane.add(progressBar);
lblProgress = new JLabel("");
lblProgress.setBounds(64, 82, 386, 58);
contentPane.add(lblProgress);
}
@Override
public Component getListCellRendererComponent(JList<? extends SpecialAttribute> list, SpecialAttribute item, int index, boolean isSelected, boolean cellHasFocus) {
JPanel panel = JPanelFactory.createBorderlessPanel();
panel.setToolTipText(item.getLongDescription());
panel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
JLabel lblItem = JLabelFactory.createJLabel(item.getDescription());
lblItem.setBounds(3, 13, 80, 20);
lblItem.setToolTipText(item.getLongDescription());
panel.add(lblItem);
JProgressBar itemProgressBar = JProgressBarFactory.createHorizontalJProgressBar(0, item.getMaxValue(), imageInfoReader);
itemProgressBar.setBounds(120, 13, 110, 20);
itemProgressBar.setValue(item.getCurrentValue());
itemProgressBar.setToolTipText(item.getLongDescription());
panel.add(itemProgressBar);
return panel;
}
private void createDeitiesPanel(World world, int infoPanelWidth, int infoPanelHeight, JPanel infoPanel) {
JPanel deitiesPanel = JPanelFactory.createJPanel("Deities");
deitiesPanel.setLayout(null);
deitiesPanel.setBounds(510, 363, infoPanelWidth + 5, infoPanelHeight);
infoPanel.add(deitiesPanel, DEITIES_KEY);
DeityAttributes deityAttributes = GroupPropertyUtils.getVillagersOrganization(world).getProperty(Constants.DEITY_ATTRIBUTES);
String deityTooltip = "deity hapiness indicator: if a deity becomes unhappy, they may lash out against the population";
for(int i=0; i<Deity.ALL_DEITIES.size(); i++) {
Deity deity = Deity.ALL_DEITIES.get(i);
Image image = imageInfoReader.getImage(deity.getBoonImageId(), null);
JLabel nameLabel = JLabelFactory.createJLabel(deity.getName(), image);
nameLabel.setBounds(15, 30 + 40 * i, 150, 50);
nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
nameLabel.setToolTipText(deityTooltip);
deitiesPanel.add(nameLabel);
JProgressBar relationshipProgresBar = JProgressBarFactory.createHorizontalJProgressBar(deityAttributes.getMinHapinessValue(), deityAttributes.getMaxHapinessValue(), imageInfoReader);
relationshipProgresBar.setBounds(175, 40 + 40 * i, 300, 30);
relationshipProgresBar.setValue(deityAttributes.getHappiness(deity));
relationshipProgresBar.setToolTipText(deityTooltip);
deitiesPanel.add(relationshipProgresBar);
}
}
private void createSkillBlock(SkillProperty skillProperty, JPanel parentPanel, int x, int y) {
String skillDescription = skillProperty.getName();
skillDescription = Character.toUpperCase(skillDescription.charAt(0)) + skillDescription.substring(1);
JLabel lblSkill = JLabelFactory.createJLabel(skillDescription);
lblSkill.setBounds(x, y, 110, 20);
lblSkill.setToolTipText(skillProperty.getLongDescription());
parentPanel.add(lblSkill);
JLabel lblSkillValue = JLabelFactory.createJLabel(playerCharacter.getProperty(skillProperty).toString());
lblSkillValue.setBounds(x + 115, y, 15, 20);
lblSkillValue.setToolTipText(skillProperty.getLongDescription());
parentPanel.add(lblSkillValue);
JProgressBar skillProgressBar = JProgressBarFactory.createHorizontalJProgressBar(0, 100, imageInfoReader);
skillProgressBar.setBounds(x + 130, y, 130, 20);
skillProgressBar.setToolTipText(skillProperty.getLongDescription());
skillProgressBar.setValue(playerCharacter.getProperty(skillProperty).getPercentageUntilNextLevelUp());
parentPanel.add(skillProgressBar);
}
private void init(String initLabel)
{
panel = new JPanel();
panel.setLayout(null);
panel.setPreferredSize(new Dimension(400, 100));
progressLabel = new JLabel(initLabel);
progressLabel.setFont(new java.awt.Font("dialog", java.awt.Font.BOLD, 12));
progressLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
progressLabel.setForeground(new java.awt.Color(0, 0, 156));
progressLabel.setBounds(30, 20, 340, 20);
panel.add(progressLabel);
progressBar = new JProgressBar(0, maxSteps);
progressBar.setStringPainted(true);
progressLabel.setLabelFor(progressBar);
progressBar.setAlignmentX(CENTER_ALIGNMENT);
progressBar.getAccessibleContext().setAccessibleName("SwingSet loading progress");
progressBar.setBounds(30, 40, 340, 20);
panel.add(progressBar);
// show the frame
this.setContentPane(panel);
this.pack();
this.setVisible(true);
WindowUtils.centerWindow(this);
setState(initLabel, 0);
}
public ShowProgressBar() {
// 创建标签,并在标签上放置一张图片
// label = new JLabel(new ImageIcon("images/background.jpg"));
label = new JLabel("数据正在处理中,请稍后... ...", SwingConstants.CENTER);
label.setFont(new Font("华文楷体", Font.ITALIC, 30));
label.setBounds(0, 0, LOAD_WIDTH, LOAD_HEIGHT - 25);
label.setBackground(new Color(204, 0, 1));// 背景色设置之后无效,不知道为何
label.setForeground(new Color(69, 133, 243));
// 创建进度条
progressbar = new JProgressBar();
// 显示当前进度值信息
progressbar.setStringPainted(true);
// 设置进度条边框不显示
progressbar.setBorderPainted(false);
// 设置进度条的前景色,即进度条的颜色
progressbar.setForeground(new Color(153, 230, 40));
// 设置进度条的背景色,即进度条的背景色
progressbar.setBackground(new Color(27, 27, 24));
progressbar.setBounds(0, LOAD_HEIGHT - 15, LOAD_WIDTH, 15);
// 添加组件
this.add(label);
this.add(progressbar);
// 设置布局为空
this.setLayout(null);
// 设置窗口初始位置
this.setLocation((WIDTH - LOAD_WIDTH) / 2, (HEIGHT - LOAD_HEIGHT) / 2);
// 设置窗口大小
this.setSize(LOAD_WIDTH, LOAD_HEIGHT);
// 设置窗口显示
this.setVisible(true);
}
/**
* Constructor with explicit title
*
* @param title dialog title
*/
public ProgressFrame(String title) {
SarosPluginContext.initComponent(this);
frmMain = new JFrame(title);
frmMain.setSize(300, 160);
projectUtils.runWithProject(
project -> frmMain.setLocationRelativeTo(WindowManager.getInstance().getFrame(project)));
Container pane = frmMain.getContentPane();
pane.setLayout(null);
frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton btnCancel = new JButton(BUTTON_CANCEL);
btnCancel.addActionListener(actionEvent -> setCanceled(true));
JProgressBar progressBar =
new JProgressBar(MonitorProgressBar.MIN_VALUE, MonitorProgressBar.MAX_VALUE);
JLabel infoLabel = new JLabel(title);
monitorProgressBar = new MonitorProgressBar(progressBar, infoLabel);
pane.add(infoLabel);
pane.add(btnCancel);
pane.add(progressBar);
infoLabel.setBounds(10, 15, 200, 15);
progressBar.setBounds(10, 50, 280, 20);
btnCancel.setBounds(100, 85, 100, 25);
frmMain.setResizable(false);
frmMain.setVisible(true);
this.frmMain.repaint();
}
/**
* Create the frame.
*/
public Update() {
//关闭进程
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 394, 124);
setVisible(true);
setLocationRelativeTo(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel label = new JLabel("进度");
label.setBounds(10, 31, 54, 15);
contentPane.add(label);
progressBar = new JProgressBar();
progressBar.setBounds(49, 32, 319, 14);
contentPane.add(progressBar);
JLabel statusLabel = new JLabel("正在更新...");
statusLabel.setBounds(161, 56, 113, 19);
contentPane.add(statusLabel);
Version version = getInfoData();
if(version!=null) {
String path = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getParentFile().getParentFile().getPath(); //获取应用文件夹路径
System.out.println(path);
path = path.substring(path.indexOf("\\") + 1);
System.out.println(path);
//path = "C:\\Users\\LGX\\Desktop\\新建文件夹";
File file = new File(path + "/wg-client-simple.jar");
System.out.println(file.getPath());
//多线程更新
new Thread(() -> {
boolean result = getStream(version, file);
if(result) {
JOptionPane.showMessageDialog(null, "更新成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "更新失败!", "提示", JOptionPane.ERROR_MESSAGE);
}
//退出系统
setVisible(false);
dispose();
}).start();
}
}
private void init() {
setUndecorated(true);
try {
if (GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
if (!Config.getInstance().isNoTransparency())
setOpacity(0.85f);
}
} catch (Exception e) {
Logger.log(e);
}
setIconImage(ImageResource.getImage("icon.png"));
setSize(getScaledInt(350), getScaledInt(200));
setLocationRelativeTo(null);
setResizable(false);
getContentPane().setLayout(null);
getContentPane().setBackground(ColorResource.getDarkestBgColor());
titlePanel = new TitlePanel(null, this);
titlePanel.setOpaque(false);
titlePanel.setBounds(0, 0, getScaledInt(350), getScaledInt(50));
closeBtn = new CustomButton();
closeBtn.setBounds(getScaledInt(320), getScaledInt(5), getScaledInt(24), getScaledInt(24));
closeBtn.setIcon(ImageResource.getIcon("title_close.png",20,20));
closeBtn.setBackground(ColorResource.getDarkestBgColor());
closeBtn.setBorderPainted(false);
closeBtn.setFocusPainted(false);
closeBtn.setName("CLOSE");
closeBtn.addActionListener(this);
minBtn = new CustomButton();
minBtn.setBounds(getScaledInt(296), getScaledInt(5), getScaledInt(24), getScaledInt(24));
minBtn.setIcon(ImageResource.getIcon("title_min.png",20,20));
minBtn.setBackground(ColorResource.getDarkestBgColor());
minBtn.setBorderPainted(false);
minBtn.setFocusPainted(false);
minBtn.setName("MIN");
minBtn.addActionListener(this);
titleLbl = new JLabel(StringResource.get("TITLE_CONVERT"));
titleLbl.setFont(FontResource.getBiggerFont());
titleLbl.setForeground(ColorResource.getSelectionColor());
titleLbl.setBounds(getScaledInt(25), getScaledInt(15), getScaledInt(250), getScaledInt(30));
JLabel lineLbl = new JLabel();
lineLbl.setBackground(ColorResource.getSelectionColor());
lineLbl.setBounds(0, getScaledInt(55), getScaledInt(400), 2);
lineLbl.setOpaque(true);
prg = new JProgressBar();
prg.setBounds(getScaledInt(20), getScaledInt(85), getScaledInt(350) - getScaledInt(40), getScaledInt(5));
statLbl = new JLabel();
statLbl.setForeground(Color.WHITE);
statLbl.setBounds(getScaledInt(20), getScaledInt(100), getScaledInt(350) - getScaledInt(40), getScaledInt(25));
titlePanel.add(titleLbl);
titlePanel.add(minBtn);
titlePanel.add(closeBtn);
add(lineLbl);
add(titlePanel);
add(prg);
add(statLbl);
panel = new JPanel(null);
panel.setBounds(0, getScaledInt(150), getScaledInt(350), getScaledInt(50));
panel.setBackground(Color.DARK_GRAY);
btnCN = new CustomButton(StringResource.get("MENU_PAUSE"));
btnCN.setBounds(0, 1, getScaledInt(350), getScaledInt(50));
btnCN.setName("CLOSE");
applyStyle(btnCN);
panel.add(btnCN);
add(panel);
}
private void init() {
setUndecorated(true);
try {
if (GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
if (!Config.getInstance().isNoTransparency())
setOpacity(0.85f);
}
} catch (Exception e) {
Logger.log(e);
}
setIconImage(ImageResource.getImage("icon.png"));
setSize(getScaledInt(350), getScaledInt(200));
setLocationRelativeTo(null);
setResizable(false);
getContentPane().setLayout(null);
getContentPane().setBackground(ColorResource.getDarkestBgColor());
titlePanel = new TitlePanel(null, this);
titlePanel.setOpaque(false);
titlePanel.setBounds(0, 0, getScaledInt(350), getScaledInt(50));
closeBtn = new CustomButton();
closeBtn.setBounds(getScaledInt(320), getScaledInt(5), getScaledInt(24), getScaledInt(24));
closeBtn.setIcon(ImageResource.getIcon("title_close.png",20,20));
closeBtn.setBackground(ColorResource.getDarkestBgColor());
closeBtn.setBorderPainted(false);
closeBtn.setFocusPainted(false);
closeBtn.setName("CLOSE");
closeBtn.addActionListener(this);
minBtn = new CustomButton();
minBtn.setBounds(getScaledInt(296), getScaledInt(5), getScaledInt(24), getScaledInt(24));
minBtn.setIcon(ImageResource.getIcon("title_min.png",20,20));
minBtn.setBackground(ColorResource.getDarkestBgColor());
minBtn.setBorderPainted(false);
minBtn.setFocusPainted(false);
minBtn.setName("MIN");
minBtn.addActionListener(this);
titleLbl = new JLabel(StringResource.get("TITLE_CONVERT"));
titleLbl.setFont(FontResource.getBiggerFont());
titleLbl.setForeground(ColorResource.getSelectionColor());
titleLbl.setBounds(getScaledInt(25), getScaledInt(15), getScaledInt(250), getScaledInt(30));
JLabel lineLbl = new JLabel();
lineLbl.setBackground(ColorResource.getSelectionColor());
lineLbl.setBounds(0, getScaledInt(55), getScaledInt(400), 2);
lineLbl.setOpaque(true);
prg = new JProgressBar();
prg.setBounds(getScaledInt(20), getScaledInt(85), getScaledInt(350) - getScaledInt(40), getScaledInt(5));
statLbl = new JLabel();
statLbl.setForeground(Color.WHITE);
statLbl.setBounds(getScaledInt(20), getScaledInt(100), getScaledInt(350) - getScaledInt(40), getScaledInt(25));
titlePanel.add(titleLbl);
titlePanel.add(minBtn);
titlePanel.add(closeBtn);
add(lineLbl);
add(titlePanel);
add(prg);
add(statLbl);
panel = new JPanel(null);
panel.setBounds(getScaledInt(0), getScaledInt(150), getScaledInt(350), getScaledInt(50));
panel.setBackground(Color.DARK_GRAY);
btnCN = new CustomButton(StringResource.get("MENU_PAUSE"));
btnCN.setBounds(0, 1, getScaledInt(350), getScaledInt(50));
btnCN.setName("CLOSE");
applyStyle(btnCN);
panel.add(btnCN);
add(panel);
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
discoFrame = new JFrame();
discoFrame.setTitle("Disco Mixer");
discoFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(
DiscoMixer.class.getResource("/resources/aurouslogo.png")));
discoFrame.setType(Type.UTILITY);
discoFrame.setResizable(false);
discoFrame.setBounds(100, 100, 606, 239);
discoFrame
.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
discoFrame.getContentPane().setLayout(null);
discoFrame.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(
final java.awt.event.WindowEvent windowEvent) {
final int confirm = JOptionPane.showOptionDialog(discoFrame,
"Are You Sure You Want to Close Disco Mixer?",
"Exit Confirmation", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == 0) {
Playlist.getPlaylist().discoOpen = false;
discoFrame.dispose();
}
}
});
final JLabel logoLabel = new JLabel("");
logoLabel.setHorizontalAlignment(SwingConstants.CENTER);
logoLabel.setIcon(new ImageIcon(DiscoMixer.class
.getResource("/resources/fmw.png")));
logoLabel.setBounds(10, 0, 580, 70);
discoFrame.getContentPane().add(logoLabel);
discoProgressBar = new JProgressBar();
discoProgressBar.setStringPainted(true);
discoProgressBar.setBounds(113, 119, 380, 49);
discoProgressBar.setVisible(false);
discoFrame.getContentPane().add(discoProgressBar);
queryField = new JTextField();
queryField.setFont(new Font("Segoe UI", Font.PLAIN, 20));
queryField.setHorizontalAlignment(SwingConstants.CENTER);
queryField.setBounds(113, 119, 380, 44);
discoFrame.getContentPane().add(queryField);
queryField.setColumns(10);
final JLabel instructionsLabel = new JLabel(
"Enter an Artist, Song or Choose from the Top 100!");
instructionsLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
instructionsLabel.setHorizontalAlignment(SwingConstants.CENTER);
instructionsLabel.setBounds(23, 81, 541, 27);
discoFrame.getContentPane().add(instructionsLabel);
discoBuildButton = new JButton("Disco!");
discoBuildButton.addActionListener(e -> {
if (!queryField.getText().trim().isEmpty()) {
discoProgressBar.setVisible(true);
YouTubeDiscoUtils.buildDiscoPlayList(queryField.getText());
} else {
JOptionPane.showMessageDialog(discoFrame,
"Please enter search query", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
});
discoBuildButton.setForeground(Color.BLACK);
discoBuildButton.setBounds(197, 174, 100, 26);
discoFrame.getContentPane().add(discoBuildButton);
top100Button = new JButton("Top Hits!");
top100Button.addActionListener(e -> {
discoProgressBar.setVisible(true);
YouTubeDiscoUtils.buildTopPlayList();
});
top100Button.setForeground(Color.BLACK);
top100Button.setBounds(307, 174, 100, 26);
discoFrame.getContentPane().add(top100Button);
Playlist.getPlaylist().discoOpen = true;
final GhostText ghostText = new GhostText("Ghost B.C.", queryField);
ghostText.setHorizontalAlignment(SwingConstants.CENTER);
discoFrame.setLocationRelativeTo(UISession.getPresenter().jfxPanel);
}