How can I make it so my JTextArea is scrollable. I want to make it so that keysDisplay has a scrollbar which can be used to scroll through the text area. I have skipped some unrealated code in jFramePrint().
public class ApplicationViewer extends JFrame {
private JTabbedPane tabs = new JTabbedPane();
private JTextArea keyGenDisplay = new JTextArea();
private JTextArea keysDisplay = new JTextArea();
private JPanel controlPanel = new JPanel();
private JButton addNumber = new JButton("Add Number");
private JButton addLetter = new JButton("Add Letter");
private JButton addHyphen = new JButton("Add Hyphen");
private JButton calculateButton = new JButton("Calculate Key");
private JTextField amountField = new JTextField("", 6);
private JLabel amountLabel = new JLabel(" Amount of Keys : ");
private JScrollPane scroll = new JScrollPane(keysDisplay);
public void jFramePrint() {
this.setLayout(new BorderLayout());
this.add(controlPanel, BorderLayout.SOUTH);
controlPanel.add(addNumber);
controlPanel.add(addLetter);
controlPanel.add(addHyphen);
controlPanel.add(amountLabel);
controlPanel.add(amountField);
controlPanel.add(calculateButton);
this.add(scroll);
this.setSize(1400, 900);
this.setTitle("Key Generator");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
keyGenDisplay.append("Key Format: ");
keysDisplay.append("Keys Here: ");
tabs.add("Key Generator", keyGenDisplay);
tabs.add("Keys", keysDisplay);
this.add(tabs);
this.setVisible(true);
}
}
private JTextArea keysDisplay = new JTextArea();
First of all you should use something like:
private JTextArea keysDisplay = new JTextArea(5, 20);
This will allow the text area to calculate its own preferred size. Scrollbars will then work properly when added to a scrollpane and more than 5 rows of text are added to the text area.
this.add(scroll);
...
this.add(tabs);
Your frame is using a BorderLayout. When you don't use a constraint then "CENTER is used by default.
You can't add multile components to the same area of the BorderLayout. So only the last component added is displayed.
Specify a different constraint for the tabs component.
Related
look here
I have to make a format like this, like make a 1,2 panel, then put a 3,1 panel on the left side. Then, I put 4 text fields in the middle left panel and one button in the bottom left panel.
I'm not sure if I can just use GridLayout or if I have to use BorderLayout too.
How can I get this organized because when I set it up, I can't get the layout right. The textfields are not in the right position, they end up on the right side.
public class CreatePanel extends JPanel
{
private Vector projectList;
private JButton button1;
private ProjectSpendingPanel spendingPanel;
private JFrame frame1;
JPanel panel1;
JPanel leftPanel;
JPanel subPanel;
GridLayout layout1;
BorderLayout layout2;
GridLayout layout3;
JLabel message;
JLabel labelName;
JLabel labelNumber;
JLabel labelLocation;
JLabel labelFunding;
JTextField textField1;
JTextField textField2;
JTextField textField3;
JTextField textField4;
//Constructor initializes components and organize them using certain layouts
public CreatePanel(Vector projectList, ProjectSpendingPanel spendingPanel)
{
this.projectList = projectList;
this.spendingPanel = spendingPanel;
//organize components here
layout1 = new GridLayout(1,2);
layout2 = new BorderLayout(1,3);
layout3 = new GridLayout(4,2);
this.setLayout(layout1);
panel1 = new JPanel(layout1);
leftPanel = new JPanel(layout3);
subPanel = new JPanel(layout2);
add(panel1);
panel1.add(subPanel);
panel1.add(leftPanel);
labelName = new JLabel("Project Name");
leftPanel.add(labelName);
textField1 = new JTextField("", 15);
leftPanel.add(textField1,BorderLayout.SOUTH);
labelName = new JLabel("Project Number");
leftPanel.add(labelName);
textField2 = new JTextField("",15);
leftPanel.add(textField2);
labelLocation = new JLabel("Project Location");
leftPanel.add(labelLocation);
textField3 = new JTextField("",15);
leftPanel.add(textField3);
labelFunding = new JLabel("Initial Funding");
leftPanel.add(labelFunding);
textField4 = new JTextField("",15);
leftPanel.add(textField4);
add(leftPanel);
button1 = new JButton("Create a project");
subPanel.add(button1,BorderLayout.SOUTH);
}
To get the result you probably intended, you need to tweak your code just a little.
Your lines
panel1 = new JPanel(layout1);
leftPanel = new JPanel(layout3);
subPanel = new JPanel(layout2);
should be altered to read
panel1 = new JPanel(new GridLayout(2, 1));
leftPanel = new JPanel(layout3);
subPanel = new JPanel(layout2);
GridLayout takes rows first, then columns. Your layout1 defines one row and two columns but you use it for the text fields and the button, so I assume the two panels need to be above each other.
Second, you need to change the order from
add(panel1);
panel1.add(subPanel);
panel1.add(leftPanel);
to
add(panel1);
panel1.add(leftPanel);
panel1.add(subPanel);
Finally, I think you need to change
add(leftPanel);
button1 = new JButton("Create a project");
to
add(spendingPanel);
button1 = new JButton("Create a project");
Adding leftPanelagain seems to destroy the layout. If you do not want to see your spendingPanel here, you could use new JPanel() instead.
Here is a screenshot of the running program
I am new to java. I am trying to implement scroll feature to my Jpanel but the schoolpane is not visible. I tried to many methods but nothing works.
public class test extends ContentPanel {
JPanel secondary;
JPanel customerType;
JPanel primary;
JPanel labelPanel;
JLabel lCustNo;
JLabel lCustName;
JLabel lTelNo;
JLabel lAddress;
JLabel lNationality;
JLabel lResident;
JLabel lVisitor;
JLabel lCustomerType;
JLabel lIdCard;
JLabel lBankName;
JLabel lPassportNo;
JLabel lVisitStart;
JLabel lVisitEnd;
JTextField tCustNo;
JTextField tCustName;
JTextField tTelNo;
JTextField tAddress;
JTextField tNationality;
JTextField tIdCard;
JTextField tBankName;
JTextField tPassportNo;
JTextField tVisitStart;
JTextField tVisitEnd;
JPanel radioButton;
JRadioButton rResident;
JRadioButton rVisitor;
ButtonGroup custType;
JScrollPane scrollBar;
JSeparator s1;
public test (String title, JPanel parent) {
super(title, parent);
secondary = new JPanel(new GridLayout(2,0));
secondary.setBounds(10, 10, 500, 800);
labelPanel = new JPanel(new GridLayout(5,2,300,20));
radioButton = new JPanel(new GridLayout(1, 4));
customerType = new JPanel(new GridLayout(3,4, 30, 20));
primary = new JPanel(new BorderLayout());
lCustNo = new JLabel("Customer No: ");
lCustName = new JLabel("Name: ");
lTelNo = new JLabel("Telephone Number: ");
lAddress = new JLabel("Address: ");
lNationality = new JLabel("Nationality: ");
lResident = new JLabel("Resident");
lVisitor = new JLabel("Visitor");
lCustomerType = new JLabel("Customer Type");
lIdCard = new JLabel("Id Card");
lBankName = new JLabel("Bank Name");
lPassportNo = new JLabel("Passport Number");
lVisitStart = new JLabel("Visit Start");
lVisitEnd = new JLabel("Visit End");
tCustNo = new JTextField(10);
tCustName = new JTextField(10);
tTelNo = new JTextField(10);
tAddress = new JTextField(10);
tNationality = new JTextField(10);
tIdCard = new JTextField(10);
tBankName = new JTextField(10);
tPassportNo = new JTextField(10);
tVisitStart = new JTextField(10);
tVisitEnd = new JTextField(10);
rResident = new JRadioButton();
rVisitor = new JRadioButton();
custType = new ButtonGroup();
customerType.add(lPassportNo);
customerType.add(tPassportNo);
customerType.add(lVisitStart);
customerType.add(tVisitStart);
customerType.add(lIdCard);
customerType.add(tIdCard);
customerType.add(lBankName);
customerType.add(tBankName);
customerType.add(lVisitEnd);
customerType.add(tVisitEnd);
custType.add(rResident);
custType.add(rVisitor);
radioButton.add(lVisitor);
radioButton.add(rVisitor);
radioButton.add(lResident);
radioButton.add(rResident);
labelPanel.add(lCustNo);
labelPanel.add(tCustNo);
labelPanel.add(lCustName);
labelPanel.add(tCustName);
labelPanel.add(lTelNo);
labelPanel.add(tTelNo);
labelPanel.add(lAddress);
labelPanel.add(tAddress);
labelPanel.add(lNationality);
labelPanel.add(tNationality);
secondary.add(customerType);
secondary.add(labelPanel);;
primary.add(secondary,BorderLayout.CENTER);
scrollBar= new JScrollPane(primary);
scrollBar.setBounds(10, 10, 400, 555);
this.add(scrollBar);
}
}
My code is above. This class extends contentPanel and contentPanel extends JPanel. Someone please help me.
Thanks.
Your scrollBar is not visible because it is not necessary. If you change JScrollPane settings, for example:
scrollBar.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollBar.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
you will see you have it, but not use it. It is because your scrollBar doesn't have a content which expands dynamically (like JTextArea for example). Your scrollBar has JPanel inside, which has size to fit all its components, so it will not be enough to add some text inside text components.
To make scroll bars visible, you can change a size of JSrollPane. However setBound() will not work if you JPanel use default FlowLayout. To use absolute positioning in JPanel you need to use null layout, what is generally not recommended and is seen as bad programming practice.
Try to delete setBound() lines and use for example scrollBar.setPreferredSize(new Dimension(400,555)); instead. You should see a difference.
I have an Interface class that extends JFrame. I am creating 3 JPanels and adding them to a Container (Border Layout) in different areas of the layout.
When I run the application, nothing shows but a blank window and a title. If I resize the application it will then show all the content and work as intended.
I'm not sure what I did differently this time, I've used this method before and it works in previous programs.
Any help is appreciated.
Here is my Interface Class Constructor code: http://pastebin.com/4UyEXsBr
Code:
public class Interface extends JFrame implements ActionListener {
private Container contentPane;
private JPanel buttonPanel, userPanel;
private JButton loginButton, createUserButton, logoutButton, withdrawButton, depositButton, switchToRegisterButton, switchToLoginButton;
private JLabel headerLabel, inputTopJTFLabel, inputPW1JPFLabel, toastLabel, inputPW2JPFLabel;
public JTextField inputTopJTF;
public JPasswordField inputPW1JPF, inputPW2JPF;
JRootPane rootPane;
public Interface(int width, int height, String title) {
//Setting up Interface
setTitle(title);
setSize(width, height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(100,100);
setVisible(true);
Font header = new Font("TimesRoman", Font.PLAIN, 50);
///////////////////////BUTTON PANEL///////////////////////
//Button Panel
buttonPanel = new JPanel();
//Buttons
//loginButton
loginButton = new JButton("Login");
loginButton.addActionListener(this);
loginButton.setAlignmentX(Component.CENTER_ALIGNMENT);
//switchToRegisterButton
switchToRegisterButton = new JButton("New User?");
switchToRegisterButton.addActionListener(this);
switchToRegisterButton.setAlignmentX(Component.CENTER_ALIGNMENT);
//switchToLoginButton
switchToLoginButton = new JButton("Switch to Login");
switchToLoginButton.addActionListener(this);
switchToLoginButton.setAlignmentX(Component.CENTER_ALIGNMENT);
switchToLoginButton.setVisible(false);
//createUserButton
createUserButton = new JButton("Register");
createUserButton.addActionListener(this);
createUserButton.setAlignmentX(Component.CENTER_ALIGNMENT);
createUserButton.setVisible(false);
//logoutButton
logoutButton = new JButton("Logout");
logoutButton.addActionListener(this);
logoutButton.setAlignmentX(Component.CENTER_ALIGNMENT);
logoutButton.setVisible(false);
//withdrawButton
withdrawButton = new JButton("Withdraw");
withdrawButton.addActionListener(this);
withdrawButton.setAlignmentX(Component.CENTER_ALIGNMENT);
withdrawButton.setVisible(false);
//depositButton
depositButton = new JButton("Deposit");
depositButton.addActionListener(this);
depositButton.setAlignmentX(Component.CENTER_ALIGNMENT);
depositButton.setVisible(false);
//Adding items to buttonPanel
buttonPanel.add(loginButton);
buttonPanel.add(switchToRegisterButton);
buttonPanel.add(switchToLoginButton);
buttonPanel.add(createUserButton);
buttonPanel.add(logoutButton);
buttonPanel.add(withdrawButton);
buttonPanel.add(depositButton);
///////////////BODY PANEL//////////////////////
//Body Panel
userPanel = new JPanel();
userPanel.setLayout(new BoxLayout(userPanel, BoxLayout.PAGE_AXIS));
//JTextFields
//inputTopJTF
Dimension inputTopJTFDimension = new Dimension(100, 20);
inputTopJTF = new JTextField();
inputTopJTF.setMaximumSize(inputTopJTFDimension);
//inputPW1JPF
Dimension inputPW1JPFDimension = new Dimension(100, 20);
inputPW1JPF = new JPasswordField();
inputPW1JPF.setMaximumSize(inputPW1JPFDimension);
//inputPW2JPF
Dimension inputPW2JPFDimension = new Dimension(100, 20);
inputPW2JPF = new JPasswordField();
inputPW2JPF.setMaximumSize(inputPW2JPFDimension);
inputPW2JPF.setVisible(false);
//JLabels
//toastLabel
toastLabel = new JLabel("Please sign in or create new account.");
toastLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
//inputTopJTFLabel
inputTopJTFLabel = new JLabel("Username:");
inputTopJTFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
//inputPW1JPFLabel
inputPW1JPFLabel = new JLabel("Password:");
inputPW1JPFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
//inputPW2JPFLabel
inputPW2JPFLabel = new JLabel("Confirm Password:");
inputPW2JPFLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
inputPW2JPFLabel.setVisible(false);
//Adding items to userPanel
userPanel.add(toastLabel);
userPanel.add(inputTopJTFLabel);
userPanel.add(inputTopJTF);
userPanel.add(inputPW1JPFLabel);
userPanel.add(inputPW1JPF);
userPanel.add(inputPW2JPFLabel);
userPanel.add(inputPW2JPF);
///////////////CONTENT PANE/////////////////////
//Content Pane
contentPane = getContentPane();
//JLabels
//headerLabel
headerLabel = new JLabel("Bank", SwingConstants.CENTER);
headerLabel.setFont(header);
//PAGE_START
contentPane.add(headerLabel, BorderLayout.PAGE_START);
//LINE_START
//CENTER
contentPane.add(userPanel, BorderLayout.CENTER);
//LINE_END
//PAGE_END
contentPane.add(buttonPanel, BorderLayout.PAGE_END);
userPanel.setFocusable(true);
userPanel.requestFocus();
//Default Button
rootPane = getRootPane();
rootPane.setDefaultButton(loginButton);
}
call
setVisible(true);
in last line .because component added after line setvisible will not be shown until you call repaint(),revalidate().when you resize ,repaint() method get called and frame will visible correctly .so call setvisible after add all component
after line rootPane.setDefaultButton(loginButton); call setvisible
rootPane.setDefaultButton(loginButton);
setVisible(true);//after add all component to frame call setvisible method
this is full working code
I am having a problem trying to layout my JFrame. I'm trying to add the ToolBar top, then Info below that, then colour below that to the right, then Copies in the center, then Print button to left and then the Printer List to the bottom. If anyone could help me in the right direction would be great.
// Declare GUI Components here
// One JToolBar & JButton
private JPanel mainPanel;
private JPanel detailPanel;
private JPanel toolBarPanel;
private JToolBar jToolbar;
private JButton jbtAdmin, jbtHelp;
// A JPanel called infoPanel & JLabel
private JPanel infoPanel;
private JLabel jlblOne;
// A JPanel called colourPanel
private JPanel colourPanel;
private JRadioButton bwRadioButton, colourRadioButton;
private ButtonGroup btg;
// A JPanel called noCopiesPanel
private JPanel noCopiesPanel;
private JLabel jlbCopies;
private JTextField jtfCopies;
// A JPanel called printerPanel
private JPanel printerPanel;
private JComboBox printerBox;
private JButton jbtPrint;
// Constructor - SetLayout & Add Components here...
// Constructor takes in the selected student and assigns it to currentStudent
public StudentFrame(Student studentIn){
// Set up currentStudent
currentStudent=studentIn;
// Set up Toolbar & add jbtAdmin
toolBarPanel = new JPanel();
toolBarPanel.add(jToolbar = new JToolBar());
jToolbar.add(jbtAdmin = new JButton("Admin"));
jToolbar.add(jbtHelp = new JButton("Help"));
// Set up called infoPanel
infoPanel = new JPanel();
infoPanel.add(jlblOne = new JLabel(currentStudent.toString(), JLabel.CENTER));
// Set up colourPanel with radioButtons
colourPanel = new JPanel(new GridLayout(2,1));
colourPanel.add(bwRadioButton = new JRadioButton("Black & White", true));
colourPanel.add(colourRadioButton = new JRadioButton("Colour"));
btg = new ButtonGroup();
btg.add(bwRadioButton);
btg.add(colourRadioButton);
// Put a TitledBorder around it
colourPanel.setBorder(new TitledBorder("Colour"));
// Set up noCopiesPanel
noCopiesPanel = new JPanel(new GridLayout(1,2));
noCopiesPanel.add(jlbCopies = new JLabel("Copies"));
noCopiesPanel.add(jtfCopies = new JTextField(3));
noCopiesPanel.setBorder(new TitledBorder("Print"));
// Set up jbtPrint JButton
jbtPrint = new JButton("Print",new ImageIcon("Images/printerIcon.png"));
jbtPrint.setHorizontalTextPosition(JButton.CENTER);
jbtPrint.setVerticalTextPosition(JButton.TOP);
jbtPrint.setFont(new Font("Helvetica", Font.BOLD, 30));
jbtPrint.setBackground(Color.LIGHT_GRAY);
jbtPrint.setMnemonic('P');
// Set up printerPanel
printerPanel = new JPanel();
String[] printerList = {"Printer 24001", "Printer 24002", "Printer 24003", "Printer 24004"};
printerPanel.add(printerBox = new JComboBox(printerList));
printerPanel.setBorder(new TitledBorder("Printers"));
detailPanel = new JPanel(new GridLayout(2,1));
detailPanel.add(infoPanel, BorderLayout.NORTH);
detailPanel.add(colourPanel, BorderLayout.WEST);
detailPanel.add(noCopiesPanel, BorderLayout.CENTER);
detailPanel.add(jbtPrint, BorderLayout.EAST);
detailPanel.add(printerPanel, BorderLayout.SOUTH);
mainPanel = new JPanel();
mainPanel.add(toolBarPanel, BorderLayout.NORTH);
mainPanel.add(detailPanel, BorderLayout.SOUTH);
this.add(mainPanel);
//this.add(detailPanel);
detailPanel = new JPanel(new GridLayout(2,1));
detailPanel.add(infoPanel, BorderLayout.NORTH);
You have the layout as GridLayout but you are trying to set BorderLayout positions. If you want to set the positions, set the layout of detailPanel to BorderLayout
mainPanel = new JPanel();
mainPanel.add(toolBarPanel, BorderLayout.NORTH);
Same as above with this case. JPanel has a default FlowLayout. You need to set the layout to BorderLayout.
You should also be adding the detailPanel to the CENTER of the mainPanel.
Also a JToolBar should be added to a container with a BorderLayout
toolBarPanel = new JPanel();
toolBarPanel.add(jToolbar = new JToolBar());
Set the toolBarPanel to BorderLayout
I'm trying to use a grid layout to make a GUI window. I add all my components and it compiles but when it runs it doesn't show anything. I'm trying to make a simple layout grouped and stacked like this.
{introduction message}
{time label
time input text}
{gravity label
gravity input text}
{answer label
answer text box}
{calculate button clear button}
Here is my code
import javax.swing.*;
import java.awt.*;
public class TurnerRandyFallingGUI extends JFrame
{
final int WINDOW_HEIGHT=500;
final int WINDOW_WIDTH=500;
public TurnerRandyFallingGUI()
{
setTitle("Falling Distance Calculator");
setSize(WINDOW_WIDTH,WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(1, 5));
//labels
JLabel introMessage = new JLabel("Welcome to the Falling distance"+
"calculator");
JLabel timeLabel = new JLabel("Please enter the amount of time "+
"in seconds the object was falling.");
JLabel gravityLabel = new JLabel("Enter the amount of gravity being "+
"forced onto the object");
JLabel answerLabel = new JLabel("Answer");
//text fields
JTextField fTime = new JTextField(10);
JTextField gForce = new JTextField(10);
JTextField answerT = new JTextField(10);
//buttons
JButton calculate = new JButton("Calculate");
JButton clr = new JButton("clear");
//panels
JPanel introP = new JPanel();
JPanel timeP = new JPanel();
JPanel gravityP = new JPanel();
JPanel answerP = new JPanel();
JPanel buttonsP = new JPanel();
//adding to the panels
//intro panel
introP.add(introMessage);
//time panel
timeP.add(timeLabel);
timeP.add(fTime);
//gravity panel
gravityP.add(gravityLabel);
gravityP.add(gForce);
//answer panel
answerP.add(answerLabel);
answerP.add(answerT);
//button panel
buttonsP.add(calculate);
buttonsP.add(clr);
setVisible(true);
}
public static void main(String[] args)
{
new TurnerRandyFallingGUI();
}
}
You've added nothing to the JFrame that your class above extends. You need to add your components to containers whose hierarchy eventually leads to the top level window, to the this if you will. In other words, you have no add(someComponent) or the functionally similar this.add(someComponent)method call in your code above.
Consider adding all of your JPanels to a single JPanel
Consider adding that JPanel to the JFrame instance that is your class by calling add(thatJPanel).
Even better would be to not extend JFrame and just to create one when needed, but that will likely be the subject of another discussion at another time.
Before setVisible (true) statement add following statements:
add (introP);
add (timeP);
add (gravityP);
add (answerP);
add (buttonsP);
There is nothing in your JFrame. That is the reason
import javax.swing.*;
import java.awt.*;
public class TurnerRandyFallingGUI extends JFrame
{
final int WINDOW_HEIGHT=500;
final int WINDOW_WIDTH=500;
public TurnerRandyFallingGUI()
{
//labels
JLabel introMessage = new JLabel("Welcome to the Falling distance"+
"calculator");
JLabel timeLabel = new JLabel("Please enter the amount of time "+
"in seconds the object was falling.");
JLabel gravityLabel = new JLabel("Enter the amount of gravity being "+
"forced onto the object");
JLabel answerLabel = new JLabel("Answer");
//text fields
JTextField fTime = new JTextField(10);
JTextField gForce = new JTextField(10);
JTextField answerT = new JTextField(10);
//buttons
JButton calculate = new JButton("Calculate");
JButton clr = new JButton("clear");
//panels
JPanel introP = new JPanel();
JPanel timeP = new JPanel();
JPanel gravityP = new JPanel();
JPanel answerP = new JPanel();
JPanel buttonsP = new JPanel();
//adding to the panels
//intro panel
introP.add(introMessage);
//time panel
timeP.add(timeLabel);
timeP.add(fTime);
//gravity panel
gravityP.add(gravityLabel);
gravityP.add(gForce);
//answer panel
answerP.add(answerLabel);
answerP.add(answerT);
//button panel
buttonsP.add(calculate);
buttonsP.add(clr);
setLayout(new GridLayout(5, 1));
this.add(introP);
this.add(timeP);
this.add(gravityP);
this.add(answerP);
this.add(buttonsP);
setTitle("Falling Distance Calculator");
this.pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
this.validate();
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new TurnerRandyFallingGUI();
}
});
}
}
Consider the following
In GridLayout, the first parameter is Rows, Second is columns
Never set the size of JFrame manually. Use pack() method to decide
the size
Use SwingUtilities.InvokeLater() to run the GUI in another thread.