Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #32565

Re: JPanel and paintComponent different results between Windows/Linux

From Jeff Higgins <jeff@invalid.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: JPanel and paintComponent different results between Windows/Linux
Date 2015-09-08 23:04 -0400
Organization A noiseless patient Spider
Message-ID <mso7kc$os0$1@dont-email.me> (permalink)
References <64b2edb0-379c-4e60-b985-891d9c0a320c@googlegroups.com> <msld73$969$1@dont-email.me> <d586lfFeu3cU1@mid.individual.net>

Show all headers | View raw


On 09/08/2015 09:37 AM, Nigel Wade wrote:
> 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.
>

Another alternative for someone who has a need for a simple
Swing executable class and doesn't wish to use the Matisse builder.

Follow the tutorial located here:
<https://platform.netbeans.org/tutorials/nbm-filetemplates.html>
to create and install his own template.

Perhaps extending the Java Main Class template such as:

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "${project.licensePath}">

<#if package?? && package != "">
package ${package};

</#if>
/**
  *
  * @author ${user}
  */
public class ${name} {

   public ${name}(String args) {
     // TODO auto generated constructor
   }

   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
     SwingUtilities.invokeLater(new Runnable() {
       public void run() {
         new ${name}(args);
       }
     });
   }
}

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

JPanel and paintComponent different results between Windows/Linux Dark Mornings <pwong18@gmail.com> - 2015-09-07 17:27 -0700
  Re: JPanel and paintComponent different results between Windows/Linux Jeff Higgins <jeff@invalid.invalid> - 2015-09-07 21:21 -0400
    Re: JPanel and paintComponent different results between Windows/Linux Jeff Higgins <jeff@invalid.invalid> - 2015-09-07 22:41 -0400
    Re: JPanel and paintComponent different results between Windows/Linux Nigel Wade <nmw@ion.le.ac.uk> - 2015-09-08 14:37 +0100
      Re: JPanel and paintComponent different results between Windows/Linux Jeff Higgins <jeff@invalid.invalid> - 2015-09-08 23:04 -0400

csiph-web