What methods get called when you resize a JFrame?

I'm using a JFrame in which the CENTER portion of the BorderLayout is occupied by a JScrollPane that wraps around a JPanel. What I'm finding is that when I initiate the action that actually causes the JPanel to be displayed, the display doesn't change. But when I resize the JFrame, the new JScrollPane has now magically appeared.

So what methods are called when you resize a JFrame? If I know, then I can call it in the code and avoid having to resize the frame just to see the results of the operation.


Asked by: Marcus424 | Posted: 21-01-2022






Answer 1

Its been a little bit since I've done swing, but from memory, calling validate() on the panel should do the trick. This will cause it and its children to have their layout calculated which is when the scrollbars decision is made. If that doesn't work, try calling validate on the frame's content pane. This is a little more costly, but may be needed if other components are being considered.

Answered by: Brad898 | Posted: 22-02-2022



Similar questions

Do methods always have to be called by an object or a class? (Java)

You can call a method using myClass.myMethod() if its a static method. If its not static, you can call using myObject.myMethod() or just myMethod(). is there any other way to call it? and are there different circumstances where you can use an object to call it and call it without an object.


java - Check if void methods were called

I'm stuck in my first jUnit Test with Mockito. I must test a method, which takes an ArrayList as parameter. In this method, there will be another class called which runs Runtimes execution. So I need to mock the class with the Runtime executions, because they want fail on Jenkins (becuase Jenkins runs on Linux). First the two classes: HandleInformation testClass; the class which will be tes...


java - Guava what methods are being called when insert and delete

I have my own cache like this: LoadingCache<String, MT> g = (LoadingCache<String, MT>) CacheBuilder .newBuilder().maximumSize(5) .build(new CacheLoader<String, MT>() { @Override public MT load(String arg0) throws Exception { System.out.println("load for key " + arg0); if...


java - Where are these methods being called from?

This question already has answers here:


java - Getting the methods called inside main method using JavaParser

I am using the JavaParser library to parse the java code and access the java code tokens. Following is my code import java.util.Vector; import com.github.javaparser.JavaParser; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.expr.VariableDeclarationExpr; import com.github.javaparser.ast.stmt.BlockStmt; import...


java - How to test that all methods of a class is not called in jMock?

Using jMock, how do I test that all methods of a certain class is not called upon invoking a method in another class? For example, if I have class A and class B: class A { void x() { } void y() { } void z() { } } class B { A a; void doNothing() { } } How do I test that the invocation of B#doNothing() doesn'...


java - how to find all methods called in a method?

how to take the methods of other classes invoked in a specific method? EXAMPLE method getItem1() public String getItem1() throws UnsupportedEncodingException{ String a = "2"; a.getBytes(); a.getBytes("we"); System.out.println(a); int t = Integer.parseInt(a); return a; } The methods called in getItem1() are:


Methods Not Being Called to Main Method (Java)

This question already has answers here:


java - How to use methods from another class, called by the client

I am making a program that lets the user call a class, like it takes a string input, then calls the run() method of that class, is there any way to do that? I was hoping something like: String inp=new Scanner(System.in).nextLine(); Class cl=new Class(inp); cl.run(); I know that the code isn't correct, but that is my main idea


Using "this" with methods (in Java)

what about using "this" with methods in Java? Is it optional or there are situations when one needs to use it obligatory? The only situation I have encountered is when in the class you invoke a method within a method. But it is optional. Here is a silly example just to show what I mean: public class Test { String s; private String hey() { return s; } public String getS(){ ...


java - Why are the methods of the Math class static?

Why are the methods of the Math class static ?


class - Java methods and classes, how do they fit together?

Currently I am writing a program for an introductory Java class. I have two pieces to my puzzle. Hopefully this is a relatively simple to answer question. Firstly, here is what I am trying to use as my main program: import java.util.Scanner; public class TheATMGame { public static void main(String[] args){ Scanner input = new Scanner(System.in); double newBalance = 0; double monthl...


jsp - What are the life cycle methods of a Java Server Page?

What are the life cycle methods of a Java Server Page?


java - How can I access methods based on strings in an array?

Hello! I'm not even sure if this is possible, but hopefully it is in Java. I know I've done it in PHP by using variable variables and accessing a variable dynamically, but I read this isn't possible in Java in a different question. I have an array of strings which contains the state of checkboxes in my JSF GUI. If all checkboxes are set the array will then be filled with strings containing...


java - Is there a neater way of testing calls to mocked methods for each item in a list

This is an example of a pattern I've encountered a lot recently. I have a method to be tested that takes a List and may invoke some other method(s) for each item in the list. To test this I define an Iterator with the expected call parameters and a loop in the JMock expectations to check the call is made against each item of the iterator (see trivial example below). I've had a look at the Hamcrest matchers but have...


java - Where methods live? Stack or in Heap?

I know that local variables and paramters of methods live in stack, but I not able to figure out where does actually methods live in case of Java? If I declare any Thread object like: Thread t=new Thread(); t.start(); So it means I've created a separate calling of methods apart from main method. What does it mean? Does it mean calling of separate sequence of methods over Stack memo...


java - How can I test final and static methods of a utility project?

I'm trying to implement unit testing for aproject, it uses a legacy "utility" project that is littered with static methods and many of the classes are final or their methods are final. I'm not able to update the legacy project at all. JMock and EasyMock both choke on final methods, and I don't see a nice way to test the static calls. What techniques are there to test these?


methods - java basics about final keyword

Can final keyword be used for a method?


java - can jax-ws web methods return objects that have static methods?

public class Pojo { private String value; public static void printValue() { System.out.println("value=" + value); } } I would want to return this from a web service as follows: @WebService public class MyService { @WebMethod public Pojo getPojo() { return new Pojo(); } } Can't seem to find the definitive answer on whether I can, shou...






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top