jdialog in non gui program

Discussion in 'Java' started by Mark, Jan 5, 2009.

  1. Mark

    Mark Guest

    I've written a program that converts list of products from our suppliers at work into a format some of our other programs understand. The program is completely non-graphical aside from when a product category is encountered that we don't have a matching code for, in which case I display a JDialog with a JTextField for someone to enter in a code.

    At the moment the whole process is run from EventQueue.invokeLater in main which works ok on my computer when it's run from within NetBeans and from the command prompt. If I run the program from the server (running XPSP2 and jre 6 update 11) then when it comes to displaying the JDialog, only the outside frame is drawn - where the controls should be I see the window behind.

    I removed EventQueue.invokeLater from main and switched to calling JDialog.setVisible inside invokeLater which had no effect.

    The import code is completely procedural - there are no listeners (apart from for a button click in the dialog class), and the dialog should and does block until a code is entered.

    Is there a way I should write the program so the dialog displays properly? Or is there a reason it would work ok on my computer and not others?

    Thanks
     
    Mark, Jan 5, 2009
    #1
    1. Advertising

  2. On Jan 5, 7:44 pm, Mark <> wrote:

    >..If I run the program from the server ..


    Could you expand on that part about the 'server'?
    Is this a web app.?

    > Is there a way I should write the program so the dialog displays properly? ...


    Probably, but without seeing an SSCCE*, it is
    difficult to determine what exactly is going
    wrong.

    * <http://pscode.org/sscce.html>

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jan 5, 2009
    #2
    1. Advertising

  3. Mark

    Mark Guest

    Andrew Thompson wrote:
    > Could you expand on that part about the 'server'?
    > Is this a web app.?


    No, desktop (although the only gui part is the dialog).

    > Probably, but without seeing an SSCCE*, it is
    > difficult to determine what exactly is going
    > wrong.


    I'll try and keep it short. The relevant part is in findOptionA.

    In Main.java:

    public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {

    try {
    Importer importer = new Importer((String)Config.getInstance().getProperty("wincatal.import_path"));
    importer.process();
    } catch (Exception e) {
    e.printStackTrace();
    }

    }
    });
    }

    In Importer.java:

    public void process() throws ConfigurationException {
    File importPath = new File(directory);
    Import curImport = null;

    try {
    curImport = new AnywareImport();
    curImport.setExporter(new Exporter(exportPath));
    curImport.processFile(file);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    In AnywareImport.java:

    public void processFile(File file) throws FileNotFoundException, IOException {
    ...
    processFile(line);
    ...
    }

    public void processLine(String[] line) throws IOException {
    Product product = findProduct(line[0].trim());
    OptionA oa = findOptionA(line[5].trim());
    ...
    }

    In Import.java:

    protected OptionA findOptionA(String desc) {
    if (desc != null && !desc.isEmpty()) {
    Query q = Importer.getEntityManager().createQuery("SELECT o FROM OptionA o " +
    "where o.supplier.code = :supplier and o.description = :description");
    q.setParameter("supplier", supplier.getCode());
    q.setParameter("description", desc.trim());

    if (q.getResultList().size() == 1) {

    OptionA oa = (OptionA)q.getSingleResult();
    oa.setSent(Short.valueOf("1"));

    persist(oa);

    return oa;

    } else {

    OptionDialog od = new OptionDialog(null, true, desc);
    od.setVisible(true); <--- this is where it stops working

    OptionA oa = new OptionA();
    oa.setCode(od.code);
    oa.setDescription(desc);
    oa.setSupplier(supplier);
    oa.setSent(Short.valueOf("1"));

    persist(oa);

    return oa;

    }
    }

    return null;
    }

    I hope that's enough and makes sense.

    Thanks
     
    Mark, Jan 5, 2009
    #3
  4. Mark

    jlp Guest

    Mark a écrit :
    > Andrew Thompson wrote:
    >> Could you expand on that part about the 'server'?
    >> Is this a web app.?

    >
    > No, desktop (although the only gui part is the dialog).
    >
    >> Probably, but without seeing an SSCCE*, it is
    >> difficult to determine what exactly is going
    >> wrong.

    >
    > I'll try and keep it short. The relevant part is in findOptionA.
    >
    > In Main.java:
    >
    > public static void main(String[] args) {
    > java.awt.EventQueue.invokeLater(new Runnable() {
    > public void run() {
    >
    > try {
    > Importer importer = new Importer((String)Config.getInstance().getProperty("wincatal.import_path"));
    > importer.process();
    > } catch (Exception e) {
    > e.printStackTrace();
    > }
    >
    > }
    > });
    > }
    >
    > In Importer.java:
    >
    > public void process() throws ConfigurationException {
    > File importPath = new File(directory);
    > Import curImport = null;
    >
    > try {
    > curImport = new AnywareImport();
    > curImport.setExporter(new Exporter(exportPath));
    > curImport.processFile(file);
    > } catch (Exception e) {
    > e.printStackTrace();
    > }
    > }
    >
    > In AnywareImport.java:
    >
    > public void processFile(File file) throws FileNotFoundException, IOException {
    > ...
    > processFile(line);
    > ...
    > }
    >
    > public void processLine(String[] line) throws IOException {
    > Product product = findProduct(line[0].trim());
    > OptionA oa = findOptionA(line[5].trim());
    > ...
    > }
    >
    > In Import.java:
    >
    > protected OptionA findOptionA(String desc) {
    > if (desc != null && !desc.isEmpty()) {
    > Query q = Importer.getEntityManager().createQuery("SELECT o FROM OptionA o " +
    > "where o.supplier.code = :supplier and o.description = :description");
    > q.setParameter("supplier", supplier.getCode());
    > q.setParameter("description", desc.trim());
    >
    > if (q.getResultList().size() == 1) {
    >
    > OptionA oa = (OptionA)q.getSingleResult();
    > oa.setSent(Short.valueOf("1"));
    >
    > persist(oa);
    >
    > return oa;
    >
    > } else {
    >
    > OptionDialog od = new OptionDialog(null, true, desc);
    > od.setVisible(true); <--- this is where it stops working
    >
    > OptionA oa = new OptionA();
    > oa.setCode(od.code);
    > oa.setDescription(desc);
    > oa.setSupplier(supplier);
    > oa.setSent(Short.valueOf("1"));
    >
    > persist(oa);
    >
    > return oa;
    >
    > }
    > }
    >
    > return null;
    > }
    >
    > I hope that's enough and makes sense.
    >
    > Thanks

    Try to add : -Dsun.java2d.d3d=false
    in the commnad line.
     
    jlp, Jan 5, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandr Molochnikov

    Re: JDialog in taskbar under Linux

    Alexandr Molochnikov, Jul 31, 2003, in forum: Java
    Replies:
    0
    Views:
    1,902
    Alexandr Molochnikov
    Jul 31, 2003
  2. Inertia_sublimation
    Replies:
    5
    Views:
    2,126
    Inertia_sublimation
    Jan 3, 2004
  3. Replies:
    8
    Views:
    18,644
    Steve W. Jackson
    Mar 2, 2006
  4. ulysses
    Replies:
    4
    Views:
    818
    Werner Schiendl
    Oct 22, 2003
  5. Hal Fulton

    GUI and non-GUI data

    Hal Fulton, Aug 5, 2004, in forum: Ruby
    Replies:
    1
    Views:
    160
    Austin Ziegler
    Aug 5, 2004
Loading...

Share This Page