Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GridLayout中的Java FlowLayout_Java_Swing_Date_Layout_User Interface - Fatal编程技术网

GridLayout中的Java FlowLayout

GridLayout中的Java FlowLayout,java,swing,date,layout,user-interface,Java,Swing,Date,Layout,User Interface,我想将日期移到左上角,但在flowlayout行中,面板元素向右移动,而不移到中心。 如何修改gridlayout以将其移动到正确的位置,或者应该使用不可见的元素填充flowlayout 谢谢 import java.util.Date; import java.awt.FlowLayout; import java.awt.GridLayout; import java.util.Calendar; import javax.swing.JFrame;

我想将日期移到左上角,但在flowlayout行中,面板元素向右移动,而不移到中心。 如何修改gridlayout以将其移动到正确的位置,或者应该使用不可见的元素填充flowlayout

谢谢

    import java.util.Date;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.util.Calendar;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;


    public class abba extends JPanel{

        Date dátum = new Date();
        Calendar cal = Calendar.getInstance();
        JLabel dát = new JLabel("Dátum: ");
        JTextArea év = new JTextArea("");
        JTextArea hónap = new JTextArea("");
        JTextArea nap = new JTextArea("");


        public class Date1 extends JPanel{

            public Date1(){

                setLayout(new FlowLayout(4));

                cal.setTime(dátum);
                int year = cal.get(Calendar.YEAR);
                int month = cal.get(Calendar.MONTH)+1;
                int day = cal.get(Calendar.DAY_OF_MONTH);

                év.setText(year+"");
                év.setColumns(4);
                hónap.setText(month+"");
                hónap.setColumns(2);
                nap.setText(day+"");
                nap.setColumns(2);

                add(dát);
                add(év);
                add(hónap);
                add(nap);
            }
        }




        public static void main(String args[]) {
            abba a = new abba();
            JFrame aa = new JFrame("Frame");
            aa.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            aa.setSize(300, 300);
            aa.add(a);
            aa.setVisible(true);
        }

        public abba(){
            setLayout(new GridLayout(10,1));
            add(new Date1());
        //...
        }
    }    
替换

setLayout(new FlowLayout(4));


使用
FlowLayout
常量字段参数而不是幻数。(4=
FlowLayout.training

而不是在网格布局中使用方框布局。
setLayout(new FlowLayout(FlowLayout.LEFT));