java - overlapping JPanels in the GUI -


i using borderlayout in application. have main panel add 2 jpanels @ center. want 1 of them transparent. code :

 mainpanel = new jpanel();  mainpanel.setlayout(new borderlayout());  mainpanel.add(getgraphpanescrollpane(), borderlayout.center);  mainpanel.add(getsituationpanel(), borderlayout.center); 

code these 2 functions :

public jscrollpane getgraphpanescrollpane() {     if (graphpanescrollpane == null) {         graphpanescrollpane = new jscrollpane();         graphpanescrollpane.setviewportview(getgrapheditorpane());     }     return graphpanescrollpane; } private jscrollpane getsituationpanel(){     if(situationpanel == null){         logs.debug("initializing situation panel");          situationpanel = new jscrollpane();          situationlabel = new jlabel("");         situationlabel.setverticaltextposition(jlabel.bottom);         situationlabel.sethorizontaltextposition(jlabel.center);         situationlabel.setverticalalignment(jlabel.top);         situationlabel.sethorizontalalignment(jlabel.center);         situationlabel.setborder(borderfactory.createtitledborder(""));         situationlabel.setbackground(color.white);         situationlabel.setopaque(true);         situationlabel.setverticalalignment(swingconstants.top);          situationpanel.setviewportview(situationlabel);       }       return situationpanel; } 

now want situationpanel transparent , getgraphpanescrollpane above in gui, because getgraphpanescrollpane canvas, use draw nodes.

i want situationpanel transparent , getgraphpanescrollpane above in gui,

the panel on top panel needs transparent. if panel on top opaque never see panel under top panel.

so making changes layout last thing want.

well going need do. can't add 2 panels 1 panel , expect work way want to. swing layout managers designed lay out components in 2 dimensions, not on top of 1 another.

your current code is:

mainpanel.setlayout(new borderlayout()); mainpanel.add(getgraphpanescrollpane(), borderlayout.center); mainpanel.add(getsituationpanel(), borderlayout.center); 

you try using overlaylayout, designed lay out panels on top of on another. code should like:

jpanel overlay = new jpanel(); overlay.setlayout( new overlaylayout(overlay) ); overlay.add(getsituationpanel(), borderlayout.center); // add transparent panel first overlay.add(getgraphpanescrollpane(), borderlayout.center); mainpanel.setlayout(new borderlayout());  mainpanel.add(overlay); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -