7f)) Ĭons.setHeight(layout.getConstraint(SpringLayout.SOUTH, contentPane)) Ĭons.setX(layout.getConstraint(SpringLayout.EAST, treePane)) Ĭons.setWidth(Spring.scale(layout.getConstraint(SpringLayout.EAST, contentPane). JTextArea area = new JTextArea("Some contents") Ĭons.setWidth(Spring.scale(layout.getConstraint(SpringLayout.EAST, contentPane). JScrollPane treePane = new JScrollPane(env) SpringLayout layout = new SpringLayout() I couldn't get Spring.width and Spring.height to work so I used a more verbose way import Here is another approach using SpringLayout. Panel.add(new JTextArea("Some contents"),c) GridBagConstraints c = new GridBagConstraints() Ĭ.gridwidth=GridBagConstraints.REMAINDER By default any component added to the panel will be centered both vertically and horizontally. The wrapper panel can use a GridBagLayout. JPanel panel = new JPanel(new GridBagLayout()) I am trying to center a 'Flowlayout'-ed JPanel vertically inside another Panel. Private static final long serialVersionUID = 1L You might play around with setMinimumSize and setPreferedSize of your components. This uses GridBagLayout to do sort of what you want. Root.add(new DefaultMutableTreeNode("three")) Root.add(new DefaultMutableTreeNode("two")) One.add(new DefaultMutableTreeNode("under one.2")) One.add(new DefaultMutableTreeNode("under one.1")) Panel.add(new JTextArea("Some contents")) ĭefaultMutableTreeNode root = new DefaultMutableTreeNode("Root") ĭefaultMutableTreeNode one = new DefaultMutableTreeNode("One") Does someone know if this can be done in Swing? (I can achieve this by setting pixel heights and layout manager but I am looking for the cleanest solution to set percentage heights and widths.) package Just say height=100% and width to be 30% etc and we are done. Understand that this is easiest to achieve in HTML. I want both of them to take 100% height and let the tree take 30% and textArea take 70% width (if the tree is expanded to 10 levels then I am ok with ScrollPane). Secondly, inside the panel I have a tree and text area. If the horizontal space in the container is too small to put all the components in one row, the FlowLayout class uses multiple rows. If I run this, I see a badly aligned UI.įirstly, I want a panel (that is inside the root frame) to take up the 100% height of frame (in this case 800px minus that little space it takes for painting the frame title). The FlowLayout class puts components in a row, sized at their preferred size. I want to set the height/width of only that frame (and I do not want to try and pixelify its children). In the code that I have pasted below for example, I have made the root frame to be 800,600. I want to make a component to occupy the maximumAvailableHeight of the Container. Each LayoutManager has its own rules for handling and respecting these dimensions so the impact of setting a preferred size on a component in a FlowLayout will.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |