Thread: Layout problems

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0

    Layout problems


    Hi!

    I have often problems with Layouts. How can I set component at exact location.
    I thought I can do
    button.setLocation(20,40) but some strange things happens all the time. The problem is with this
    Layouts (Flow, Grid, Border...). In C# I think there are not these problems.
    Can I turn off all these layouts and put things much simpler. At this time I have this code and when I run this
    the table is not showed at window?

    public class nothing extends JFrame {

    private JTable tabpredmet;

    public nothing () {
    super("govno");
    setLayout(null);
    setSize(400, 700);
    setVisible(true);

    String[][] data = new String[][]{{"Srpski jezik"}, {"Engleski jezik"}, {"Ruski jezik"}};
    String[] col = {"Predmet"};
    tabpredmet = new JTable(data, col);
    tabpredmet.setPreferredScrollableViewportSize(new Dimension(200, 200));
    tabpredmet.setFillsViewportHeight(true);
    // JScrollPane jscrollpane = new JScrollPane(tabpredmet);
    JScrollPane p = new JScrollPane(tabpredmet);
    add(p);
    p.setVisible(true);
    p.setLocation(50, 50);

    }

    public static void main(String[] args) {
    nothing a = new nothing ();
    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);




    }
    }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    You can remove the LayoutManager completely. You would position components absolutely. The drawback would be it wouldn't scale nicely.

IMN logo majestic logo threadwatch logo seochat tools logo