layout-manager

GridBagLayout: equally distributed cells

谁都会走 提交于 2019-12-19 12:54:07
问题 Is it possible to completely emulate the behavior of a GridLayout with the GridBagLayout manager? Basically, I have a 8x8 grid in which each cell should have the same width and height. The GridLayout automatically did this. But I want to add another row and column to the grid which size is not the same as the other ones. That row/column should take up all the remaining space that might be left over (because the available size couldn't be equally distributed into 8 cells). Is that even

Component on JPanel not showing when setLayout(null)

人盡茶涼 提交于 2019-12-19 10:59:08
问题 Someone can tell why the combobox is not showing ? I have a Controller: public class TestController extends JPanel { TestView cgView; public TestController() { setLayout(null); cgView=new TestView(); add(cgView); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame fr = new JFrame("testt"); fr.setSize(1200,1000); fr.setResizable(false); TestController cgc=new TestController(); fr.setBackground(Color.white); fr.setVisible(true); fr

Stack swing elements from top to bottom

那年仲夏 提交于 2019-12-19 10:19:10
问题 Consider the following figure: I need to develop a swing GUI the looks like this. I simply named them jLabel's but there a few images and jLabels in it. The default awt background visible is a JPanel and each red background visible is a serperate JPanel. Now I need them to get stacked as shown above. I tried a number of LayoutManagers and still it doesn't work. The important point here is that the number of red colored divs are not constant. If there is only one red colored div then it must

Giving a JPanel a percentage-based width

梦想的初衷 提交于 2019-12-19 09:41:16
问题 What's the easiest way to make a JPanel that takes up a fixed percentage of its parent container, by width? Its width should update when that of its parent container changes. I tried using Box.createHorizontalStrut() , but that doesn't update when the width of the JPanel 's parent container changes. 回答1: What you want is a GridBagLayout. (How to use?) Using a GridbagLayout allows you to define GridBagConstraints for each single component you add. These constraints include weightx which does

Grid bag layout not displaying the way I want

僤鯓⒐⒋嵵緔 提交于 2019-12-19 04:03:03
问题 So I have 6 panels, all of them used a grid layout. And I put them together using gridbaglayout, here is the design I wanted Turn out it became a total mess The "second" panel became much further away to the right The third panel is squeezed a lot to the left and it was a disaster. Here is my code for the gridbag layout c.gridx = 0; c.gridy = 0; add (first,c); c.gridx = 2; //so that the second panel starts from the center and is divided evenly with the first panel add(second,c); c.gridx = 0;

Including more than two Panels in a JFrame?

旧城冷巷雨未停 提交于 2019-12-19 03:54:14
问题 We are working on a project where we encountered a problem with including more than two Panels on the same JFrame .What we want is one Panel above the other. Can the community help give an example of ho to implement this or refer me to a good tutorial or guide related to our Java Swing needs? 回答1: Assuming you want two panels added to a single frame: Set a layout for your parent JFrame and add the two panels. Something like the following JFrame frame = new JFrame(); //frame.setLayout(); - Set

java GridBagLayout anchor

吃可爱长大的小学妹 提交于 2019-12-19 03:12:35
问题 Learing GridBagLayout, The issue here is, the name label and combox don't show up on the top of the panel, but I have set its anchor to NORTH. Why ? import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.WindowConstants; public class Test2 { public Test2() { JFrame frame = new JFrame(); frame.setTitle("test"); frame

How can I control the width of JTextFields in Java Swing?

女生的网名这么多〃 提交于 2019-12-18 18:47:09
问题 I am trying to have several JTextFields on a single row, but I don't want them to have the same width. How can I control the width and make some of them wider than others? I want that they together take up 100% of the total width, so it would be good if I could use some kind of weigthing. I have tried with .setColumns() but it doesn't make sense. Here is an example, where I am using three rows with three strings that should appear as in columns: import java.awt.GridLayout; import javax.swing

jQuery Layout Manager

风流意气都作罢 提交于 2019-12-18 10:09:29
问题 Has anyone had any experience with a jQuery-based layout manager? I know of only one (JX) but it's somewhat bloated for my needs. Any thoughts? 回答1: Thought these links may help... jQuery UI.Layout Plug-in 6 Flexible jQuery Plugins To Control Webpage Layouts Easily 11 Best jQuery Layout Plugins 回答2: I have used the Docking Layout Manager plugin with good success. Its pretty simple and fairly small, about 7 kb uncompressed. 回答3: The Magic jQuery plugin at : http://www.jquery-css.com/magic

more efficient layout than Box

假如想象 提交于 2019-12-18 08:59:02
问题 I've got some very old code which uses a Box to list some information. I create it like so: Box patterns = Box.createVerticalBox(); Very (very) often, new items are added and old items are removed eg: label = new JLabel("xyz"); patterns.add(label); and later patterns.remove(label); whenever something is added ore removed I have to have it repaint, so I call: patterns.revalidate(); patterns.repaint(); Problem is, since this happens very often it chokes up the UI. I think I need a better