java - How to recreate this progress bar based JFrame? -
i'm wanting create jframe
, found perfect frame. want recreate this:
the code frame looks this:
progressbar = new jprogressbar(); statuslbl = new jlabel(); statuslbl1 = new jlabel(); percentlbl = new jlabel(); setdefaultcloseoperation(windowconstants.exit_on_close); settitle("auto-updater"); addwindowlistener(new windowadapter() { public void windowclosing(windowevent evt) { formwindowclosing(evt); } }); statuslbl.settext("status:"); statuslbl1.settext("n/a"); percentlbl.settext("0%"); grouplayout layout = new grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup(layout.createparallelgroup(grouplayout.alignment.leading).addgroup( layout.createsequentialgroup() .addcontainergap() .addgroup(layout.createparallelgroup(grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcomponent(statuslbl).addpreferredgap(layoutstyle.componentplacement.related) .addcomponent(statuslbl1).addpreferredgap(layoutstyle.componentplacement.related, 304, 32767) .addcomponent(percentlbl)).addcomponent(progressbar, grouplayout.alignment.trailing, -1, 380, 32767)) .addcontainergap())); layout.setverticalgroup(layout.createparallelgroup(grouplayout.alignment.leading).addgroup( layout.createsequentialgroup() .addcontainergap() .addgroup(layout.createparallelgroup(grouplayout.alignment.leading, false) .addgroup(layout.createparallelgroup(grouplayout.alignment.baseline) .addcomponent(statuslbl1, -1, -1, 32767) .addcomponent(percentlbl)) .addcomponent(statuslbl, -1, -1, 32767)).addpreferredgap(layoutstyle.componentplacement.related) .addcomponent(progressbar, -2, 30, -2).addcontainergap(-1, 32767))); pack();
but think looks ugly , has 0 readability, i'm asking you: how can recreate frame using different layout or how can use layout differently make readable?
if progress string included within progress bar done single jpanel
borderlayout
. put label in page_start
, progress bar in center
(which default if no constraint specified).
note: i'd tend display panel in jdialog
or joptionpane
rather jframe
, here frame based version.
import java.awt.*; import javax.swing.*; import javax.swing.border.emptyborder; public class progressbarpanel { private jcomponent ui = null; progressbarpanel() { initui(); } public void initui() { if (ui!=null) return; ui = new jpanel(new borderlayout(4,4)); ui.setborder(new emptyborder(4,4,4,4)); jprogressbar progressbar = new jprogressbar(0, 100) { public dimension getpreferredsize() { // base on multiple of default preferred size // account size of font used paint // progress string return new dimension(400,40); } }; progressbar.setvalue(50); progressbar.setstringpainted(true); ui.add(progressbar); ui.add(new jlabel("status: n/a"), borderlayout.page_start); } public jcomponent getui() { return ui; } public static void main(string[] args) { runnable r = new runnable() { @override public void run() { try { uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname()); } catch (exception usedefault) { } progressbarpanel o = new progressbarpanel(); jframe f = new jframe(o.getclass().getsimplename()); f.setdefaultcloseoperation(jframe.dispose_on_close); f.setlocationbyplatform(true); f.setcontentpane(o.getui()); f.pack(); f.setminimumsize(f.getsize()); f.setvisible(true); } }; swingutilities.invokelater(r); } }
Comments
Post a Comment