layout-manager

GridBagLayout does not display a component

风格不统一 提交于 2020-05-17 06:26:07
问题 I wrote a component to display a circular progressbar. When I put it in BorderLayout everything looks fine. But it can't be seen when a GridBagLayout is set. p.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; p.add(north(), gbc); gbc.gridx = 0; gbc.gridy = 1; p.add(west(), gbc); gbc.gridx = 1; gbc.gridy = 1; p.add(bar, gbc); I have no idea whether it is the problem of setting the GridBagConstraints or other reasons. 回答1: But it

Is SpringLayout a fixed-size layout manager?

冷暖自知 提交于 2020-03-05 00:23:06
问题 I know the following Java Swing layout managers: FlowLayout , BoxLayout , BorderLayout , GridLayout , GroupLayout (which I avoid using), and GridBagLayout . I call GridBagLayout a fixed-size layout manager as it defines rows and columns with fixed size. I would not use it in a responsive application if I want all my panels to be resizable. I would try to combine a few of the other layout managers instead. Out of curiosity I'm considering adopting a new layout manager, SpringLayout , for an

Is SpringLayout a fixed-size layout manager?

99封情书 提交于 2020-03-05 00:22:46
问题 I know the following Java Swing layout managers: FlowLayout , BoxLayout , BorderLayout , GridLayout , GroupLayout (which I avoid using), and GridBagLayout . I call GridBagLayout a fixed-size layout manager as it defines rows and columns with fixed size. I would not use it in a responsive application if I want all my panels to be resizable. I would try to combine a few of the other layout managers instead. Out of curiosity I'm considering adopting a new layout manager, SpringLayout , for an

suitable LayoutManager for resizable components

对着背影说爱祢 提交于 2020-02-15 07:21:06
问题 sometime ago I read this article that shows a way to implement mouse resizable components in Swing. The author uses a null LayoutManager in order to allow absolute component positioning. I know that a null layout should never be used, so my question is: is there any already implemented LayoutManager that allow component's absolute positioning, or I have to implement it my own? 回答1: A layout manager really does 3 things: Set the location of a component. Since you need the ability to drag the

How to align JPanel to bottom of JFrame (java swing)

三世轮回 提交于 2020-02-08 07:40:35
问题 Long story short, I'm making a simple audio player in Java and am starting the GUI; no events, no functionality of any kind as of yet. I'm asking how I can the JPanel with the buttons (controls), to align to the bottom center of the main window (JFrame). Here's the code. import javax.swing.*; import java.awt.*; public class tryingtowindow extends JFrame { //Buttons public JButton rewind; public JButton play; public JButton fastForward; //the window public JFrame UI; public JPanel controls; /

How to specify Jlist width?

无人久伴 提交于 2020-02-01 09:12:06
问题 I want to specify fixed width of my JList I followed example provided by Gilbert Le Blanc 22k getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); Panel panel = new JPanel(); panel.setBackground(Color.WHITE); getContentPane().add(panel); String [] queries = {"a", "b", "a", "b" , "a", "b", "a", "b"}; panel.setLayout(new BorderLayout()); JList list = new JList(queries); list.setMaximumSize(new Dimension(200, 200)); // this line does not do the job list.setMinimumSize

How to specify Jlist width?

*爱你&永不变心* 提交于 2020-02-01 09:12:06
问题 I want to specify fixed width of my JList I followed example provided by Gilbert Le Blanc 22k getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); Panel panel = new JPanel(); panel.setBackground(Color.WHITE); getContentPane().add(panel); String [] queries = {"a", "b", "a", "b" , "a", "b", "a", "b"}; panel.setLayout(new BorderLayout()); JList list = new JList(queries); list.setMaximumSize(new Dimension(200, 200)); // this line does not do the job list.setMinimumSize

BoxLayout refuses to honor preferred size of JButton

混江龙づ霸主 提交于 2020-01-21 15:26:45
问题 I have been working on a small project that is supposed to simulate a gambling game. Unfortunately, I ran into some odd issues while working with BoxLayout . To the best of my knowledge, LayoutManager s usually honor any component's preferred size. However, in the below code, BoxLayout does not. Here is my code thus far: import java.awt.*; import javax.swing.*; public class Main { public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(

BoxLayout refuses to honor preferred size of JButton

混江龙づ霸主 提交于 2020-01-21 15:25:33
问题 I have been working on a small project that is supposed to simulate a gambling game. Unfortunately, I ran into some odd issues while working with BoxLayout . To the best of my knowledge, LayoutManager s usually honor any component's preferred size. However, in the below code, BoxLayout does not. Here is my code thus far: import java.awt.*; import javax.swing.*; public class Main { public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(

Which Layout Manager to use? [closed]

别说谁变了你拦得住时间么 提交于 2020-01-21 10:20:10
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . So basically I want to create this sort of a GUI, but because of my inexperience with Java GUIs, I cannot figure out which Layout Manager to use. I've tried Flow, Border, Grid, but none of them allow me to create