java splitpane help code terminates when i run it

Shez Khan

When i try to run this code i get a message in the run console saying the operation has been terminated, however there are no errors in the code and everything appears to be fine

public class Component1 extends JFrame 
{
    public Component1 () {

        setTitle("GUI");
        setSize(150, 150);

        //The code below creates the two panels of the UI And they are both labelled with names.
        JPanel jsp1 = new JPanel();
        JPanel jsp2 = new JPanel();
        JLabel j1 = new JLabel("Left Side");
        JLabel j2 = new JLabel("Right Side");

        //jsp1 and jsp2 work together with the code above to create the two panels of the interface by adding "J1" and "J2" this allows 
        //both sides to be labelled and appear on the UI        

        jsp1.add(j1);
        jsp2.add(j2);   

        JSplitPane splitPane = new
JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
            true, jsp1, jsp2);

        splitPane.setOneTouchExpandable(true);
        getContentPane().add(splitPane);
    }

    public static void main(String[] args) 
    {
        Component1 sp = new Component1 ();
        sp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        sp.setVisible(true);
    }
    Component1panel panel = new Component1panel ();
}
Tadija Bagarić

You exit your application when your main() ends. You should start a thread that holds your frame.

Try editing your main to this (fix imports if needed):

public static void main(String[] args){
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            // build and show your GUI               

            Component1 sp = new Component1 ();
            sp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            sp.setVisible(true);
        }
    });
}

Also, maybe a link to a JFrame hello-world will help: link

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

When I run this code only the Splitpane shows up but not the JMenu

when i run my code this error show up pls help: The build failed. Fix the build errors and run again

Terminate process run with `exec` when program terminates

I need help understanding this java code

How do I get my code to work?The loop somehow terminates when it shouldn't do so

I am trying to run the following java code in netbeans but when i run the code i get thr following exceptions

AsynchTask should not stop when I terminates Application

when I run this code in Pycharm i didn't get any outputs simply it shows------ process finished with exit code 0. please help me with this issue

I got a mistake when I run the this code:

Java program terminates when delay time is long

gettting this error when i try to run eclipse in ubuntu please help

I'm getting java.sql.SQLSyntaxErrorException when I run the code given below

I've got Could not find or load main class when I try to run my java code

When I try to run my code with the "java" command in the cmd window, I get an error

Why do I get a redundant % (percent sign) when I run Java code in VSCode?

I'm trying to sort my created data set in SAS, but now even when I remove the sorting function, my code does not run, can someone help me?

I need help to move div when on Key Code 39 and 37

turtle screen crashes when I run the code

None output when I run my code

camera suddenly close when i run the code

code error when i run the code in code block compiler

Java trouble with ArrayLists when there are multiple classes and help fixing up the code

0 I've installed the vs code extension Code Runner to help me run C language programs but it doesn't run my code

why is it giving me an java.util.InputMismatchException when i run this code when I use a text file with the text (shown underneath)

How to create a unique value each time when ever I run the java-script code?

So when I deploy my code to CloudBees global.java won't run (Play Framework 2.1)

How do I fix Java Eclipse "Launch Error" when trying to run code?

Why is this error occuring when i run my java code using JOptionPane?

Can someone please help me with the code I am writing? (Java)

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive