layout-manager

How to add JLabel at run time in Swing?

蓝咒 提交于 2020-07-20 01:17:50
问题 I am making am window application on Java. I want to add label name at run time in my Swing application. How can I do this using Java Swing? public class Component1 extends JPanel { Component1() { JLabel label = new JLabel("dd"); label.setBounds(370, 340, 150, 20); // label.setText("labeVVl"); add(label); } public static void main(String[] args) { // create frame JFrame frame = new JFrame(); final int FRAME_WIDTH = 800; final int FRAME_HEIGHT = 600; // set frame attributes frame.setSize(FRAME

BoxLayout for a JFrame

冷暖自知 提交于 2020-07-03 09:23:40
问题 Could you help me understand what is going on here. I consulted Javadoc: JFrame has setLayout method. So, what sharing error springs out is a mystery to me. public class View extends JFrame { public View(){ // LayoutManager for the whole frame. this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); } } Result Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared at javax.swing.BoxLayout.checkContainer(BoxLayout.java:465) at javax.swing.BoxLayout.invalidateLayout(BoxLayout

BoxLayout for a JFrame

核能气质少年 提交于 2020-07-03 09:22:57
问题 Could you help me understand what is going on here. I consulted Javadoc: JFrame has setLayout method. So, what sharing error springs out is a mystery to me. public class View extends JFrame { public View(){ // LayoutManager for the whole frame. this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); } } Result Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared at javax.swing.BoxLayout.checkContainer(BoxLayout.java:465) at javax.swing.BoxLayout.invalidateLayout(BoxLayout

wrong parent for CardLayout in java

孤街浪徒 提交于 2020-05-30 11:27:13
问题 I want to change cards in my CardLayout (which contains labels) for every choice in my combo box. So when I select Item2 in the combo box it should show the second card but it returns error instead. Inside the method initComponents() I successfully showed the first card using cardLayout.show(imagePanel, "1"); but when I tried to do the same inside private void comboMenuActionPerformed() , it returns the error "IllegalArgumentException: wrong parent for CardLayout". Why is this happening?

GridBagLayout with glue : no fixed row height

旧巷老猫 提交于 2020-05-17 07:42:53
问题 I would like to create a panel, to which I can dynamically add sub-panels with fixed height. I tried using a glue component, but it does not work. I would like to achieve that the sub-panels are visible at the top of the gridbaglayout. Side problem is that when I keep adding sub-panels, they start to overlap because the JScrollPane isn't adjusting. However, when I resize the frame, both problems are solved. At this moment I don't see where I went wrong. Why does the glue component not take up