Nathaniel Oriecuia
Nathaniel Oriecuia

Reputation: 21

java jframe window not resizing

When I run my program, the window is smaller than it should be looking at my design tab for creating a JFrame.

Does anyone know why this is happening and how to fix this?

It keeps cutting off the bottom of my program no matter what adjustments I make.

The code:

private void solveButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        //recieving variable A
        String inputA = txtInputA.getText();
        double varA = Double.parseDouble(inputA);

        //recieving variable B
        String inputB = txtInputB.getText();
        double varB = Double.parseDouble(inputB);

        //recieving variable C
        String inputC = txtInputC.getText();
        double varC = Double.parseDouble(inputC);

        //pluging the variables into the quadratic formula (solving for x)
        double varX = Math.sqrt((varB * varB) - (4.0 * varA * varC));
        varX = (-varB + varX) / (2.0 * varA);
        double varX2 = Math.sqrt((varB * varB) - (4.0 * varA * varC));
        varX2 = (-varB - varX2) / (2.0 * varA); 

        //rounding results 
        varX = Math.round(varX * 100.0) / 100.0;
        varX2 = Math.round(varX2 * 100.0) / 100.0;

        //displaying results to user
        txtOutput.setText("X = " + varX + "            " + "X = " + varX2);

Upvotes: 1

Views: 63

Answers (3)

MadProgrammer
MadProgrammer

Reputation: 347184

After adding your components to the frame, call pack on the frame, it will use the container's layout manager to calculate the preferred viewable size and pack the frame around it

Upvotes: 1

Arpit Porwal
Arpit Porwal

Reputation: 293

JFrame frameobject = new JFramee(); frameobject.setResizable(true);

It will solve your re-sizing problem.

Upvotes: 0

Aaronward
Aaronward

Reputation: 119

The maths calculations seems redundant here so i don't understand why you included it. But it could be possible one of your components have a set minimum or maximum size, which could be whats messing up the size. Edit your question with the sufficient code for people to get a better understanding of the problem and come to a conclusion.

Upvotes: 0

Related Questions