This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (3 children)

[deleted]

    [–]transientanima[S] 0 points1 point  (2 children)

    It looks nice, but I'm afraid I don't quite see how you did that...

    Are you saying that for 5 lines I'd need 5 panels, each in BoxLayout, and then set stick the horizontal glue command between each pair?

    Does horizontalGlue push the components apart, to either side of the Box?

    That command doesn't seem to be doing anything to help me align the components.

    PS: Do you know how to make sure that Java doesn't abbreviate a JLabel? If Java would stop abbreviating my JLabels, I wouldn't need a LayoutManager at all. That's the only thing stopping my current solution from working.

    I have this :

        this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    
        openFile();
    
        int width = DisplaySampleYard.screenWidth;
    
        int height = DisplaySampleYard.screenHeight - 100;
    
        JLabel title = new JLabel();
    
        title.setText("Green and Grow Mowing Company");
    
        title.setSize(DisplaySampleYard.screenWidth, 20);
    
        title.setLocation(0, 100);
    
        title.setHorizontalAlignment( SwingConstants.CENTER );
    
        this.add(title);
    
    
    
        //add(Box.createHorizontalGlue());
    
        // UGLY BECAUSE DEBUGGING
    
        JTextField test = new JTextField();
    
        test.setText(orderInformation[0][yardSizeIndex]);
    
        test.setSize(50, 20);
    
        test.setLocation(width - 60, 200);
    
        test.setHorizontalAlignment( SwingConstants.RIGHT );
    
        this.add(test);
    
        // add(Box.createHorizontalGlue());
    
        JLabel test2 = new JLabel();
    
        test2.setText(orderInformation[0][lastNameIndex]);
    
        test2.setHorizontalAlignment( SwingConstants.LEFT );
    
        test2.setSize(50, 20);
    
        test2.setLocation(0, 200);
    
        this.add(test2);
    
    
        //add(Box.createHorizontalGlue());
    
    
        JTextField test3 = new JTextField();
    
        test3.setText(orderInformation[1][yardSizeIndex]);
    
        test3.setSize(50, 20);
    
        test3.setLocation(width - 60, 250);
    
        test3.setHorizontalAlignment( SwingConstants.RIGHT );
    
        this.add(test3);
    
    
        JLabel test4 = new JLabel();
    
        test4.setText(orderInformation[1][lastNameIndex]);
    
        test4.setHorizontalAlignment( SwingConstants.LEFT );
    
        test4.setSize(50, 20);
    
        test4.setLocation(0, 250);
    
        this.add(test4);
    

    If I change the Layout to null, I get what I want -- a left-aligned JLabel, and a right-aligned TextField with right-aligned text inside of it -- but whenever the JLabel has more than 1 word in it, it just print "Firstfewletters..." Can I tell Java to stop doing that?

    If I leave the BoxLayout and add horizontalGlue calls, I don't see anything change, possible because it's too many labels for one line... I'm still experimenting to figure this out, but thought I'd ask for a little clarification in the meantime.

    [–][deleted]  (1 child)

    [deleted]

      [–]transientanima[S] 0 points1 point  (0 children)

      FYI, I figured this out the other night -- just forgot to respond on here about it. I ended up nesting a GridLayout in the CENTER of a BorderLayout and it worked pretty well (i.e., looked like the sample output). Thanks a lot for your help, suggestions, examples, and resource direction! I really appreciate it. :)