Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: How to fix annoying white splash in this simple java code?

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to fix annoying white splash in this simple java code?

    The problem is when I run the code below, I see a white splash on my screen for about maybe 100ms which is extremely annoying:

    import java.awt.*;
    import javax.swing.*;
     
    public class MyPanel extends JPanel {
     
        public MyPanel() {
            this.setBackground(Color.black);
            JTextArea jtext = new JTextArea(10, 20);
            jtext.setBackground(Color.black);
            jtext.setForeground(Color.white);
            jtext.setText("some stuff here");
            add(jtext);
            add(new JButton("some button"));
            // TODO: gui elements
        }
     
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("MyPanel");
                    frame.getContentPane().add(new MyPanel());
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    frame.setVisible(true);
                }
            });
        }
    }

    My entire work setup is in dark theme. Equivilant code written in C++ with Qt does not show any white splashs on the same system. I'm using Ubuntu 12.04 and Intel HD Graphics 3000. Please let me know how this can be fixed. I googled this problem but all I found was: "how to create splash screen in java?" which what I'm trying to avoid.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,166
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: How to fix annoying white splash in this simple java code?

    Hard to help you, as I don't see the white flash on my machine (Windows 7).

    Maybe try googling "flash" instead of "splash".
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How to fix annoying white splash in this simple java code?

    Quote Originally Posted by t342532 View Post
    The problem is when I run the code below, I see a white splash on my screen for about maybe 100ms which is extremely annoying:
    Try to color with black also the content pane:

    frame.getContentPane().setBackground(Color.BLACK);
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to fix annoying white splash in this simple java code?

    Quote Originally Posted by andbin View Post
    Try to color with black also the content pane:

    frame.getContentPane().setBackground(Color.BLACK);
    no difference

  5. #5
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How to fix annoying white splash in this simple java code?

    Quote Originally Posted by t342532 View Post
    no difference
    Ok, try on frame directly:

    frame.setBackground(Color.BLACK);
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How to fix annoying white splash in this simple java code?

    Quote Originally Posted by KevinWorkman View Post
    Hard to help you, as I don't see the white flash on my machine (Windows 7).
    Same results on Windows XP, XP Pro, Vista; Ubuntu 10.04 & 12.10

  7. #7
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to fix annoying white splash in this simple java code?

    FIXED it!
    I'm not sure why this works:
    I extended MyPanel to JFrame and put most of the functions there. then in the run() invoked it and set visible to true.
    here is the code:

    import java.awt.*;
    import javax.swing.*;
     
    public class MyPanel extends JFrame {
     
        public MyPanel() {
     
        	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        	this.setBackground(Color.black);
            JTextArea jtext = new JTextArea(10, 20);
            jtext.setBackground(Color.black);
            jtext.setForeground(Color.white);
            jtext.setText("some stuff here");
            getContentPane().add(jtext);
     
            // TODO: gui elements
     
            setExtendedState(JFrame.MAXIMIZED_BOTH);
            setSize(350, 250);
            setLocationRelativeTo(null);
        }
     
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                	MyPanel mypanel = new MyPanel();
                	mypanel.setVisible(true);
                }
            });
        }
    }

  8. #8
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How to fix annoying white splash in this simple java code?

    Quote Originally Posted by t342532 View Post
        	this.setBackground(Color.black);
    This was conceptually my last hint.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

Similar Threads

  1. Please help! Passing variables between modules.
    By Aberdeen in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 7th, 2013, 10:18 PM
  2. [SOLVED] New to JAVA, problem with first code, need to know how to fix.
    By hrenfrow in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 22nd, 2013, 10:17 AM
  3. JAVA SPLASH SCREEN
    By kvv230892 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 18th, 2012, 06:48 AM
  4. Annoying null pointer exception in my code
    By oyinig in forum Member Introductions
    Replies: 1
    Last Post: July 13th, 2012, 08:06 PM
  5. please help? simple fix that someone who knows bout java can prolly help me
    By joelmeler in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 11th, 2011, 01:33 PM

Tags for this Thread