swing - Add 3 panels to a frame in java with JSplitPane? -
trying add 3 panels created frame in java jsplitpane. have tried 2 panels, , worked great, 3 still not want.
have read making 2 jsplitpanes , put 1 in other, not work do.
my code shows there 3 panels, size wrong.. should filled out.
my code:
frame = new jframe(); // create new frame frame.setvisible(true); // makes visible frame.setsize(900, 500); // sets size frame.settitle(""); // sets title frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setlocationrelativeto(null); // sets window on center of screen temp_panel = new jpanel(); // creates new jpanel water_panel = new jpanel(); // creates new jpanel power_panel = new jpanel(); // creates new jpanel temp_panel.setbackground(color.decode("#2ecc71")); // sets color water_panel.setbackground(color.decode("#3498db")); // sets color power_panel.setbackground(color.decode("#f1c40f")); // sets color temp_label = new jlabel("this temperature"); water_label = new jlabel("this water consumption"); power_label = new jlabel("this power consumption"); // add labels on panel temp_panel.add(temp_label); water_panel.add(water_label); power_panel.add(power_label); jsplitpane splitpaneleft = new jsplitpane(jsplitpane.horizontal_split); jsplitpane splitpaneright = new jsplitpane(jsplitpane.horizontal_split); splitpaneleft.setleftcomponent( temp_panel ); splitpaneleft.setrightcomponent( water_panel ); splitpaneright.setleftcomponent( splitpaneleft ); splitpaneright.setrightcomponent( power_panel ); splitpaneleft.setenabled(false); splitpaneleft.setdividersize(0); splitpaneright.setenabled(false); splitpaneright.setdividersize(0); // put splitpaneright onto single panel jpanel panelsplit = new jpanel(); panelsplit.add( splitpaneright ); frame.add(panelsplit, borderlayout.center);
it should this, 3 panels 3 different colors instead of 2!
hope can help
if don't need change relative sizes of components during runtime, don't use jsplitpane. instead create container jpanel uses gridlayout, new gridlayout(1, 0)
1 row , variable number of columns, add 3 colored jpanels gridlayout-using jpanel, , add jframe.
Comments
Post a Comment