Tuesday, 15 March 2011

swing - Java JPanel Reusable view -



swing - Java JPanel Reusable view -

i have created set of buttons want @ top of every page of application.

rather having recreate setup in every class, possible create 1 time , include in every class, similar reusable view in android.

my code button setup below:

public buttons() { setlayout(null); jbutton btnnewbutton = new jbutton("new button"); btnnewbutton.setbounds(10, 11, 89, 23); add(btnnewbutton); jbutton btnnewbutton_1 = new jbutton("new button"); btnnewbutton_1.setbounds(101, 11, 89, 23); add(btnnewbutton_1); jbutton btnnewbutton_2 = new jbutton("new button"); btnnewbutton_2.setbounds(192, 11, 89, 23); add(btnnewbutton_2); textfield_2 = new jtextfield(); textfield_2.setbounds(104, 42, 86, 20); add(textfield_2); textfield_2.setcolumns(10); system.out.println("hello"); }

my code create class below:

public static void gui(){ frame = new jframe("name"); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setresizable(true); frame.setlayout(new borderlayout()); frame.add(new buttons(), borderlayout.west); frame.pack(); frame.setlocationrelativeto(null); frame.setvisible(true); frame.setbounds(200, 0, 500, 500); }

i have tried adding next line method add together sec set of buttons:

frame.add(new extras(), borderlayout.center);

but adds sec object display.

create class (or method) creates jpanel holds buttons want. then, add together new instance of jpanel gui. pseudo-code:

public jpanel createbuttons() { jpanel panel = new jpanel(); // add together buttons panel homecoming panel; } public void gui() { frame = new jframe("name"); frame.setlayout(new borderlayout()); frame.add(createbuttons(), borderlayout.west); // ... }

java swing user-interface layout-manager uicollectionreusableview

No comments:

Post a Comment