Question

I have the following swing layout defined in one of my classes and I cannot make out any sense of what is going on.

private void initComponents()
    {
        locationPanel = new JPanel();
        label1 = new JLabel();
        lastUpdateLabel = new JLabel();
        label2 = new JLabel();
        accuracyLabel = new JLabel();
        batteryPanel = new JPanel();
        batteryLabel = new JLabel();
        label3 = new JLabel();
        cc = new CellConstraints();

        setLayout(new FormLayout("default", "default"));

        locationPanel.setBorder(new TitledBorder("Info"));
        locationPanel.setLayout(new FormLayout("right:pref, 6dlu, 50dlu, 4dlu, default", "pref, 3dlu, pref, 3dlu, pref"));


        label1.setText("Last Update:");
        locationPanel.add(label1, cc.xy(1, 1));

        lastUpdateLabel.setText("Unknown");
        locationPanel.add(lastUpdateLabel, cc.xy(3, 1));


        label2.setText("Accuracy:");
        locationPanel.add(label2, cc.xy(1, 3));

        // ---- accuracyLabel ----
        accuracyLabel.setText("Unknown");
        locationPanel.add(accuracyLabel, cc.xy(3, 3));

        label3.setText("Battery Level");
        locationPanel.add(label3, cc.xy(1, 5));


        batteryLabel.setText("Unknown");
        locationPanel.add(batteryLabel, cc.xy(3, 5));

        add(locationPanel, cc.xy(1, 1));
    }

QUESTION: I think its saying there should be 3 rows and 2 columns? How many rows and columns are defined; how would I make a 4 x 2 layout? How do I determine what this is saying locationPanel.setLayout(new FormLayout("right:pref, 6dlu, 50dlu, 4dlu, default", "pref, 3dlu, pref, 3dlu, pref"));

Was it helpful?

Solution

http://www.java2s.com/Code/Java/Swing-Components/FormLayoutExplicitAlignmentExample3.htm

You're layout has 5 columns and 3 rows. You can deduce that well from the examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top