0

I've been going over this code for ages, and have no idea how to get my JProgressBar to actually appear on the GUI. When I run the app, the JLabel appears in the JPanel, but the JProgressBar does not, how do I fix this?

(note: the JProgressBar does work and updates, it just doesn't appear on the GUI)

jPanel9.setLayout(new BorderLayout());
    jPanel9.add(new JLabel(theTask.getName() + theTask.getDes()), BorderLayout.NORTH);
    JProgressBar progress = new JProgressBar(0, theTask.getMax());
    progress.setStringPainted(true);
    progress.setBorderPainted(true);
    progress.setValue(theTask.getProgress());
    progress.setString(theTask.getProgress() + "/" + progress.getMaximum());
    progress.setPreferredSize(new Dimension(100,100));
    progress.setVisible(true);
    jPanel9.add(progress, BorderLayout.SOUTH);
    jPanel9.revalidate();
    jPanel9.repaint();

    System.out.println(progress.getString());
    System.out.println("Progress: " + theTask.getProgress());
    System.out.println("Max: " + theTask.getMax());
rgollum
  • 1
  • 1

1 Answers1

0

I resolved the issue by making a custom panel, and dropping it into my gui in place, not quite what I wanted, but it got the job done:

public class ProgressPanel extends javax.swing.JPanel {

/**
 * Creates new form ProgressPanel
 */
public ProgressPanel() {
    initComponents();
    jProgressBar1.setMinimum(0);
}

public ProgressPanel(int max, String s)
{
    jProgressBar1.setMinimum(0);
    jProgressBar1.setMaximum(max);
    changeLabel(s);
    initComponents();
}

public void setMax(int i)
{
    jProgressBar1.setMaximum(i);
}


public void changeProgress(int i)
{
    jProgressBar1.setValue(i);
    jProgressBar1.setString(i + "/" + jProgressBar1.getMaximum());
}


public void changeLabel(String s)
{
    jLabel1.setText(s);
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jProgressBar1 = new javax.swing.JProgressBar();

    setLayout(new java.awt.BorderLayout());

    jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setText("jLabel1");
    add(jLabel1, java.awt.BorderLayout.PAGE_START);

    jProgressBar1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    add(jProgressBar1, java.awt.BorderLayout.CENTER);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JProgressBar jProgressBar1;
// End of variables declaration
rgollum
  • 1
  • 1