Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nigel Wade Newsgroups: comp.lang.java.programmer Subject: Re: JPanel and paintComponent different results between Windows/Linux Date: Tue, 08 Sep 2015 14:37:51 +0100 Lines: 31 Message-ID: References: <64b2edb0-379c-4e60-b985-891d9c0a320c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net XkYXdkgCoOeGiDNe7Tja2wNdph4zbcaFkDDDnehskgDnfXaahG Cancel-Lock: sha1:wGCgbTlLKIY0hsiKfHrwE+Nryoc= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:32559 On 08/09/15 02:21, Jeff Higgins wrote: > On 09/07/2015 08:27 PM, Dark Mornings wrote: >> Hello. I have a small program that displays a bar graph of 5 bars of varying lengths. The bars display in Windows but >> not in Linux. I used NetBeans 8/JDK 1.8 to compile the code in Windows and OpenJDK in Ubuntu 14.04. I know >> paintComponent() is called because I inserted a println() statement into the body of the do-while loop and saw the >> output. It seems paintComponent() is called 3 times. >> >> Why does the my program work in Windows but not in Linux? >> > > You have code that needs to run on the AWT event thread; > > public static void main(String args[]) { > SwingUtilities.invokeLater(new Runnable() { > public void run() { > new BarGraph(); // or however you want to arrange it. > } > }); > > You should handle your InputDialog cancel option. > > To the OP: If you are using NetBeans and create a "new JFrame Form" (in the "new" menu) it will do the boiler-plate for you. It's then up to you to design the form either in Matisse, or by editing the constructor and adding code after initComponents(). Be aware, though, that the default action for "new JFrame Form" is to add a pack() at the end of initComponents(). If you add components to the GUI after initComponents() they might not be properly packed. You can modify the default action (JFrame Properties, Code tab, Form Size Policy option) and manually pack() at the end of the constructor.