java - JTextArea in GridBagLayout stealing too much space -
i have gridbaglayout, , reason jtextarea has decided doesn't want hear gridbag's ratio with, , when create panel contains layout textbox grows till takes 1/2 of screen. heres code:
tp = new jtabbedpane(); tp.setfont(main.f); //adds tabs several buttosn tabbed pane for(menu menu : filemanager.menus){ jpanel tmp = new jpanel(); int s = (int) math.ceil(math.sqrt(menu.products.size())); tmp.setlayout(new gridlayout(s,s)); for(product p : menu.products){//act p.setfont(main.f); p.addactionlistener(this); tmp.add(p); } tp.addtab(menu.name,null,tmp,null); } receipt.setborder(borderfactory.createetchedborder()); //starting gridbag setlayout(new gridbaglayout()); gridbagconstraints gbc = new gridbagconstraints(); gbc.fill = gridbagconstraints.both; gbc.ipadx = 0; gbc.ipady = 0; //sets , adds jtabbedpane gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.8; gbc.weighty = 0.8; add(tp,gbc); //sets , adds receipt - 1 takes half screen gbc.fill = gridbagconstraints.both; gbc.gridx = 1; gbc.gridy = 0; gbc.weightx = 0.2; receipt.seteditable(false); receipt.settext("ticket number: 0\n" + "transaction number: 0\n"); receipt.setlinewrap(true); add(receipt,gbc); //sets , adds jpanel has bunch of buttons on it(uses gridlayout) gbc.fill = gridbagconstraints.both; gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 2; gbc.gridheight = 1; gbc.weightx = 1; gbc.weighty = 0.2; add(buttons,gbc); buttons.setlayout(new gridlayout(1,8)); createbutton(newtable); createbutton(remove); for(jbutton : quicks) createbutton(a); createbutton(pay); createbutton(exit); revalidate(); repaint(); when alter textarea blank jbutton doesn't take much space @ all. space filled object on right. how tell gridbag want left object span 4/5ths of screen, , right object span lastly 1/5th? in version effort using weighting, in original version attempted using cells, left object @ gridx=0 gridwidth = 4, , right object gridx = 4 gridwidth = 1
neither way worked. open alternate ideas(like improve layouts, or jtable?)
thanks help, chase
what it's doing dimensions should
if not fixed on exactly 4/5 , 1/5 ratio, can utilize borderlayout , place buttons center , text area east.
border layout display text area wide supply - specify preferred size (width, can set height whatever number want, border layout ignore it). rest of space taken buttons panel.
you can larn more border layout here: http://docs.oracle.com/javase/tutorial/uiswing/layout/border.html
java swing gridbaglayout
No comments:
Post a Comment