0

I have created a GUI via Netbeans Java but whenever I maximize the GUI window the text boxes become misaligned. I used the Netbeans drag and drop function to create the GUI. I was wondering why the text boxes become misaligned whenever I maximize the GUI

2
  • 2
    Because something's wrong in the code. How do you want us to answer such a question? Seriously? We're not extra-lucid. My advice: learn how layout managers work, and forget about the drag 'n drop tools. Code the UI by yourself. Commented Jul 26, 2013 at 16:30
  • 1
    try to use LayoutManager that are robust instead of mattise magic Commented Jul 26, 2013 at 16:53

2 Answers 2

1

It's an issue with the layout.

Read up on using layouts: http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

If you are going to use Netbean's GUI builder, run through a tutorial. It'll help you better understand how the builder is to be used. https://netbeans.org/kb/docs/java/quickstart-gui.html

Sign up to request clarification or add additional context in comments.

Comments

1

I Understood your problem because I already had the same problem, My advice to you is that you can use the drag and drop of netbeans but before using it first make a panel and in that panel drop all your stuff then using the JFrame Component re sized function just put the panel wherever you want to put it for e.g if you want to center align it.

//if your class is extending JFrame
public static int getWIDTH(){
    return WIDTH;
}
public static int getHEIGHT() {
    return HEIGHT;
}
private void formComponentResized(java.awt.event.ComponentEvent evt) {
    // this is for setting panel in the middle of the JFrame horizontally
    int a = getWIDTH();
    int b = Panel.getWidth();
    a = a/2;
    b = b/2;
    int centerForX = b - a;
    // This is for setting the panel in the middle vertically
    int x = getHEIGHT();
    int y = Panel.getHeight();
    x = x/2;
    y = y/2;
    int centerForY = x - y;
    // Making a 'Point' object and then setting location of the Panel.
    Point p = new Point(centerForX , centerForY);
    Panel.setLocation(p);
}

Some Keypoints:
1) getWIDTH and getHEIGHT methods will be generated by netbeans write outside all methods but in the class the getwidth and getheight and press ctrl + space and press enter and the getWIDTH and getHEIGHT methods will be generated respectively.
2) the formComponentResized method will be generated by netbeans, just go to design tab and then in the Navigator which is mostly in the bottom left right click on JFrame and then goto events then components and then componentResized.
3) If you have any question don't hesitate to ask, as I have detailed knowledge of this topic.

donot forget this step otherwise whole help will be of no use

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.