layout-manager

Java - set the exact position of a JComponent

徘徊边缘 提交于 2021-02-10 18:25:35
问题 I need help with setting the x and y position of a JLabel on a JPanel, not North,South,West,East. Thank you for your time. 回答1: To have a JPanel respect exact locations, you should set its layout to null. Then, you can use setLocation on any JComponent to set its location within that JPanel. JPanel panel = new JPanel(); panel.setLayout(null); JLabel label = new JLabel("text"); label.setLocation(50, 20); panel.add(label); However, note that there are several downsides of absolute position

GridLayoutManager Customization

梦想与她 提交于 2021-02-10 05:49:30
问题 i want to know if there is way that i can customize gridlayoutmanager in android to have horizontal layout like this sketch: i tried some layout manager that i found in Github but non of them that help me to implement this kind of layout manager. something like this: public class CustomLayoutManager extends StaggeredGridLayoutManager { public CustomLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public

BoxLayout: can't setup child component size

谁说我不能喝 提交于 2021-02-05 09:32:13
问题 I have a JFrame - SuperTest and JPanel - SuperLogin . The login panel has the username and password input fields and a login button. I want it to look like this: but it looks like the pic below, with input fields having too huge height and width. SuperTest.java : import javax.swing.*; public class SuperTest extends JFrame { public SuperTest() { add(new SuperLogin()); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(600, 400); } public static void main(String[

How to align multiple elements below each other?

本小妞迷上赌 提交于 2021-02-05 07:36:38
问题 I am having difficulty in aligning Swing elements flow below each other. Using GridLayout does not help me because it divides screen to rows which have equal sizes. I need to put one component to each row and the next component should be in very bottom of the last component. Mi problem is that if the choices of the question are more than one line, this layout squeeze them to the rows and there is a huge gap between picture and question "3+3?" 回答1: You can use GridBagLayout for this. It is

Not all of my JButtons are showing up after I add a dozen of them. What am I doing wrong?

烂漫一生 提交于 2021-01-29 22:43:24
问题 I want to add 52 buttons in a JPanel. All with ActionListeners. When I reach a certain amount (13) and run the program, not all of the buttons show up. For example I've added 15 buttons and only 9 or 12 of them show up. Sometimes all of them, but not every time. Here's the code for two of the JButtons: JButton button_one=new JButton(); button_one.setPreferredSize(new Dimension(100,150)); mainpanel.add(button_one); button_one.addActionListener(new ActionListener(){ @Override public void

Not all of my JButtons are showing up after I add a dozen of them. What am I doing wrong?

北城余情 提交于 2021-01-29 22:40:49
问题 I want to add 52 buttons in a JPanel. All with ActionListeners. When I reach a certain amount (13) and run the program, not all of the buttons show up. For example I've added 15 buttons and only 9 or 12 of them show up. Sometimes all of them, but not every time. Here's the code for two of the JButtons: JButton button_one=new JButton(); button_one.setPreferredSize(new Dimension(100,150)); mainpanel.add(button_one); button_one.addActionListener(new ActionListener(){ @Override public void

Not all of my JButtons are showing up after I add a dozen of them. What am I doing wrong?

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 22:02:13
问题 I want to add 52 buttons in a JPanel. All with ActionListeners. When I reach a certain amount (13) and run the program, not all of the buttons show up. For example I've added 15 buttons and only 9 or 12 of them show up. Sometimes all of them, but not every time. Here's the code for two of the JButtons: JButton button_one=new JButton(); button_one.setPreferredSize(new Dimension(100,150)); mainpanel.add(button_one); button_one.addActionListener(new ActionListener(){ @Override public void

Buttons overlap or disappear

你。 提交于 2021-01-29 20:24:08
问题 I have an example of a error in my program. I created 4 buttons: 1, 2, 3, 4. Button 2 overlaps button 4, and i just added events for 2 and 4. If I click on Button 2, it will be hidden, and Button 4 will be displayed. And if I click on Button 4, Button 2 will be displayed, and Button 4 will be covered by Button 2 again. As if anything happened, but, when I click on Button 1 or Button 3 after doing the above, Button 4 will be displayed, when I point at it (not click), it will disappear. public

How do I put two Jpanels/Jbuttons in the borderlayout north section?

二次信任 提交于 2021-01-29 07:36:29
问题 How do I display two JPanels in the 'North' in borderlayout? Here's and example code that outputs a GUI with three distinct rows, Top, Middle, Bottom. There's one button covering the first row, 3 buttons covering the second row, and one covering the bottom row. package borderLayoutDemo; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.BorderLayout; public class BorderLayoutDemo { public static void main(String[] args) { JFrame

How do I put two Jpanels/Jbuttons in the borderlayout north section?

♀尐吖头ヾ 提交于 2021-01-29 07:30:38
问题 How do I display two JPanels in the 'North' in borderlayout? Here's and example code that outputs a GUI with three distinct rows, Top, Middle, Bottom. There's one button covering the first row, 3 buttons covering the second row, and one covering the bottom row. package borderLayoutDemo; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.BorderLayout; public class BorderLayoutDemo { public static void main(String[] args) { JFrame