You can set the title bar at the time of initializing the JFrame as follows
JFrame frame = new JFrame("My Title");
or you can create a public method for your custom class like
public void setTitle(String title){ frame.setTitle(title); // for this you have declare the frame object as global for this class only }
and use this method
MyJFrame myframe = new MyJFrame(); myframe.setTitle("my new title"); myframe.setVisible(true);
source share