Messy Swing code

Hello there,
I'm a uni student and since starting learning java, we have always had it drilled into us about creating neat code which is nicely commented and has methods small enough to fit into one page (so you don't have to scroll up and down when looking at one method). Now I am learning Swing and it seems like a waste of effort to keep my methods really short. My question is regarding the 'best practice' when writing Swing code, does it really matter if I have a method createJMenuBar() which is 15 times taller than my screen or should I break it up into methods - one method per JMenuItem? It seems daft but I thought I'd ask.
Thanks
Jack
Edited by: jackCharlez on Nov 20, 2009 4:56 PM

does it really matter if I have a method createJMenuBar() which is 15 times taller than my screenWell, in my editor I can display about 50 lines of code per screen. So that would be about 750 lines of code which sounds a bit excessive to me. Many classes aren't even that big.
I can't possibly think why your menubar would take that many lines of code. But an easy way to break it up would be to have a method for creating each menu, which I think is better than one method per menu item.

Similar Messages

  • Auto-generated Swing Code: jbInit()

    Hi,
    I noticed that the auto-generated code for Swing apps directly uses class member variables, which is far from ideal. For example:
    public class Screen {
        private JLabel boardingPassLabel = new JLabel();
        public void jbInit() {
            boardingPassLabel.setText("Boarding Pass");
            boardingPassLabel.setBounds(new Rectangle(170, 25, 115, 20));
            boardingPassLabel.setFont(new Font("Tahoma", 1, 12));
    }The issue is that instantiating Screen will cause a JLabel to also be instantiated. While this is fine for a single screen and a single label, if there are hundreds of screens, each with twenty labels and buttons, it quickly gets out of hand.
    It would be nice to see the following code auto-generated:
    public class Screen {
        private JLabel boardingPassLabel;
        public void jbInit() {
            JLabel boardingPassLabel = getBoardingPassLabel();
            boardingPassLabel.setText("Boarding Pass");
            boardingPassLabel.setBounds(new Rectangle(170, 25, 115, 20));
            boardingPassLabel.setFont(new Font("Tahoma", 1, 12));
        public JLabel getBoardingPassLabel() {
          if( boardingPassLabel == null ) {
            boardingPassLabel = createBoardingPassLabel();
          return boardingPassLabel;
        protected JLabel createBoardingPassLabel() {
          return new JLabel();
    }This allows subclasses to provide a different subclass of JLabel (if needed). It also means that there is little overhead to instantiating the Screen class. Thus if we had to instantiate 100 screens, each with 20+ widgets, there would be no performance hit.
    As a work-around, we can simply not instantiate the Screen classes until just before they are used. This may not work in our situation, though.
    Thoughts?
    D

    I should probably add a detail here.
    We are running the Swing app on the CrEme JVM under Windows CE on a 520 MHz hand-held device with at most 256 MB of memory. (The specs say 520 MHz; but runs slower in practice.) Thus we need a lot more control over object instantiation, as has been described.
    It would be nice to see a "use lazy initialization" checkbox for the auto-generated code. Or perhaps a "generate and use accessors" checkbox.
    Note that the following code contains a redundancy:
        private JLabel boardingPassLabel = null;The assignemnt to null is superfluous; it adds about 50 more bytes to the final class size (using Sun's javac). It can be omitted for class member variables.
    D

  • I need help, I have alot of questions too (swing, code, optimizing...)

    Hi, I'm having a little trouble with aligning my GUI correctly. Here are screenshots from my laptop which runs OS 10.4 & my PC running Windows 2000:
    http://kavon89.googlepages.com/clipper.png <= On the laptop
    http://kavon89.googlepages.com/clipper_windows2000.jpg <= On the PC
    I don't know why the OS 10.4 looks almost perfect and the win 2k is a disaster. I played with it on my laptop and once i came over to my PC to post a problem about somthing else, i noticed this issue on my windows box. My guess is that either the JButton on OS 10.4 is smaller than the one for win2k and causing the automatic organizing to malfunction... or maybe the pixels are larger on my PC then on my laptop.
    I was thinking that I should make diffrent .jar's for each OS since there are GUI issues.... or is there a way to make it universal? (i read somwhere about GridBag?)
    Next off, Is there any way to reduce the size of the space between the JList box closest to the top of the frame & the buttons & text box below it? I tried all sorts of resizing and it seems stuck on some sort of space there which i would like to make compact.
    Those are all the swing questions i have ^
    About my code:
    I recently added 2 buttons which are at the bottom of the OS 10.4 screenshot, Clear Box & Drop All. Clear Box is the one I made work, or so I thuoght. I wrote this for my Clear Box button (by the way, the button is sapose to just clear the text box directly to the upper left of itself.)
           if(e.getSource() == buttonc)
               textfield.setText("");
           }I thought that was the best way to go about clearing the text box. just setting it to blank. But after some testing to ensure there were no reprocussions, I found a problem... When i select somthing from my JList and hit Clear Box, it deletes the entry in the JList when it is not sapose to. It also does it when there is text in the textbox and i have selected somthing in my JList. I haven't been able to figure out why. Here is my full source code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class winclipstart
      JButton buttona, buttond, buttonc, buttonda;
      DefaultListModel clippedtxt = new DefaultListModel();
      JTextArea textfield;
      JList ClippedLines;
      public static void main(String[] cheese){new winclipstart().buildGUI();}
      public void buildGUI()
        JFrame frame;
        Container contentPane;
        JPanel Bottom = new JPanel();
        JPanel Top = new JPanel();
        frame = new JFrame();
        frame.setTitle("Clipper 0.1 Beta");
        contentPane = frame.getContentPane();
        ClippedLines = new JList(clippedtxt);
        JScrollPane scroll2 = new JScrollPane(ClippedLines, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll2.setPreferredSize(new Dimension(400,150));
        textfield = new JTextArea(3,20);
        JScrollPane scroll1 = new JScrollPane(textfield, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        buttona = new JButton("Clip");
        buttond = new JButton("Drop");
        buttonc = new JButton("Clear Box");
        buttonda = new JButton("Drop All");
        Bottom.add(scroll1);
        Bottom.add(buttona);
        Bottom.add(buttond);
        Bottom.add(buttonc);
        Bottom.add(buttonda);
        Top.add(scroll2);
        Box All = Box.createVerticalBox();
            All.add(Top);
            All.add(Box.createVerticalStrut(5));
            All.add(Bottom);
        contentPane.add(All);
        buttonL cl = new buttonL();
        buttona.addActionListener(cl);
        buttond.addActionListener(cl);
        buttonc.addActionListener(cl);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.setSize(424,314);
        ClippedLines.setDragEnabled(true);
      public class buttonL implements ActionListener
        public void actionPerformed(ActionEvent e)
           if(e.getSource() == buttona)
              String elementToAdd = textfield.getText();
              if(elementToAdd.equals("")==false) clippedtxt.addElement(textfield.getText());
           else
             int index = ClippedLines.getSelectedIndex();
             if(index > -1) clippedtxt.remove(index);
           if(e.getSource() == buttonc)
               textfield.setText("");
    }There is a stray dragenabled true line in there which on my ibook showed that it drags after holding the mouse button down a little longer than expected, and it shows im dragging , but obiously not dropping because i haven't configured dropping yet. but on my windows machine it shows nothing of it. oh and, on the ibook it shows it with a green "+" and then makes it look like im trying to put it inbetween two other lines but does nothing when dropped like expected
    Another question: In the beginning of my code i have it loading the entire library with the *, and i noticed after turning it into a .jar that it loads slower than i expected... would a way to speed it up be to specify exactly what i need loaded after the program is finished or would it make no diffrence?
    :-/ seems my program isn't as cross platform as i exptected java to be

    I solved the code problem myself after a careful run through of the code, the "else" in my subclass made it so that every button other than the Add button deleted a selected entry, i quickly fixed it and made it an if statement.
    Thank you for the link cotton.m
    My question bout optimizing still remains though:In the beginning of my code i have it loading the entire library with the *, and i noticed after turning it into a .jar that it loads slower than i expected... would a way to speed it up be to specify exactly what i need loaded after the program is finished or would it make no diffrence?

  • Can't see imported swing code in jDeveloper visual designer

    Hi,
    I developed a small swing utility program in either Eclipse or NetBeans (it's been a while, and i forgot which one I used last). I'm now trying to use jDeveloper for all java development, but ran into this problem: when I look at my JFrame in the visual designer, I see the outer frame object, but none of the nested controls inside (buttons, tabbed panes, etc.). I can see all the code and I see the objects in Structure panel. I know when I migrated between Eclipse and NetBeans I had to make some changes to my code to make it work with the visual designers there. I'm pretty shocked to have the same problem in jDeveloper. Any ideas?
    Thanks,
    Dennis

    That is happening because you must follow some requirements
    if you want to import code and use the visual designer tool:
    - It must be a Java file.
    - It must be free from syntax errors.
    - It must contain a public class (the file name must be the same as the name of the
    public class).
    - It must follow JDeveloper coding conventions:
    * All UI controls are declared as class members or as local variables within jbInit().
    * All UI property settings done in jbInit(). This is necessary in order for the
    JDeveloper UI Editor and Property Inspector to reflect the settings.
    * All property settings set as expressions involve only member UI controls or
    static values.
    - It must have a default constructor.
    Any file that meets the above requirements can be visually designed using the UI Editor and the Property Inspector. You can also visually design a non-UI class.
    Hope this helps !
    Luis R.

  • Some abnormality between java 1.5 and 1.4 swings code

    Hi
    my requirement: i need to show the popup size of a combo box(whose size is preffered size) to be as large as largest item in the combobox items. so i have written a popupmenu listener. which works fine in java 1.4 but in 1.5 the popup is shown abnormally.
    abnormality is combobox list content is centered in the popup and also shows the list content incompletely.
    below is the fragment of code for popup listener
    import java.awt.Component;
    import java.awt.Dimension;
    import javax.swing.JComboBox;
    import javax.swing.JComponent;
    import javax.swing.JPopupMenu;
    import javax.swing.JScrollPane;
    import javax.swing.JViewport;
    import javax.swing.event.PopupMenuEvent;
    import javax.swing.event.PopupMenuListener;
    public class ComboBoxPopupMenuListener implements PopupMenuListener{
         public void popupMenuCanceled(PopupMenuEvent e) {
         public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
         public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
              JComboBox box = (JComboBox) e.getSource();
              Object comp = box.getUI().getAccessibleChild(box, 0);
              if (!(comp instanceof JPopupMenu)) {
                   return;
              JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
              if (scrollPane instanceof JScrollPane) {
                   JScrollPane sp = (JScrollPane) scrollPane;
                   Dimension size = scrollPane.getPreferredSize();
                   Component []comps = ((JScrollPane) scrollPane).getComponents();
                   for (int i = 0; i < comps.length; i++) {
                        if(comps[i] instanceof JViewport)
                             JViewport view = (JViewport) comps;
                             size.width = (int) (view).getViewSize().getWidth();
                   sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                   scrollPane.setPreferredSize(size);
    i have an alternative to this as providing tool tips or changing combo box to list. but can you please tell me where i am doin wrong                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    below is the fragment of code for popup listenerand what do you expect us to do with that?

  • Swing code help

    Guys,
    Thanks first of all to those of you who have been a great help over the past few days. I have one last problem that i'm not sure how to tackle.
    I'm doing a theatre booking system which has a GUI. My main screen is using a card layout.
    I have a theatre class, a booking class, performance and seating classes. I want to implement code for making a booking which will display a graphical representation of the seats for a particular section of the theatre. My seating is divided into stalls, royal circle, upper circle etc. Each of these blocks of seating has x rows and y columns.
    I want to show on a panel all seats. Booked ones coloured red, free ones coloured green - or some other approach which would be just as effective. I want to click a seat or several seats to book them for one customer.
    What approach is best for this problem? How should I draw the seats? Line drawings? Components? Suggestions on how to tackle this problem please.
    Many thanks.

    How bout this:
    Create your own subclas of Shape (sub class Rectangle if you just want your seats as rectangles or if they need to be a more complicated shape use Polygon) but add your own field colour (of type Color!, defaulted to green) which has a getter and a setter method for colour (or just setred, setgreen methods) and just one constuctor which takes a location. size and colour are set by default in the constructor. Iterate over your x and y axis creating these and storing them in an array, something line:
    int xmax = 5;
    int ymax = 3;
    int gap = 5;
    Seat[] seats = new Seat[xmax * ymax]; //Where seat is you Shape (also array should be class level)
    int count = 0;
    for (int  x = 0; x < xmax; x++){
       for (int y = 0; y < ymax; y++){
           seats[count] = new Seat( gap * x, gap * y); //Obviously this would be alot more complicated if you use Polygon as all points would need offsetting by x, y.
    }then in your draw method:
    for (allseats using i) {
         Seat seat = seats;
    g2.setColor(seat.getColour());
    g2.draw(seat)
    Add a mouselistener to the component you are drawing on which checks if a seat was clicked on:
    mouseClicked(MouseEvent me {
    for (allseats using i) {
         Seat seat = seats;
    if (seat.contains(me.getPoint()) {
    seat.setColour(Color.RED);
    //And anything else you want to do
    repaint();
    None of this is very thought through and all just typed straight into reply box so probably loads of little mistakes and improvements but somewhere to start from perhaps.
    Hope this helps,
    Alex.

  • Messy Catalyst code view

    Hello
    I have a simple project consisting of a custom/generic component. Through the course of creating this file, I've added and deleted objects from the library panel... So one would think they were gone, right?
    Well, when I look at the Code view, I see that they are still there. It still remembers everything I've added, regardless of the fact that I deleted them in design view.
    Is there some way to clean this up before I get it to FB, because trying to figure out WHICH objects I'm actually using is daunting if it has to be done in the code.
    Thanks
    Kristin

    OK.  Bad installation. Do a clean re-install with the CC Cleaner Tool.
    http://helpx.adobe.com/creative-suite/kb/cs5-cleaner-tool-installation-problems.html
    Nancy O.

  • Managing big messy complex code

    So, I'm planning on doing some conversion of about 800K (compressed) of C source to C++.  It's already in a nice C-OO style of coding.  That is:
    struct xyz { ... };
    void xyz_move(struct xyz* pxyz, ...other args...)
    void xyz_add(struct xyz* pxyz, ...other args...)
    Yet it's also written K&R style which died in the 80s...
    void
    xyz_something(pxyz, a, b, c, d)
    struct xyz *pxyz,
    int a, b
    char *c
    int d
    ...body here
    So the conversion isn't that hard.  The problem is that it's totally and wickedly unorganized... i.e. one file has 3 C "classes" listed, as well as the prototypes for 2 of the function sets.  The other function set is in a different header, and all 3 are in their own implementation files, along with other random functions prototyped in a totally different header.
    Short story: it's a mess.  I'd like to convert it to a nice 1-to-1 header/implementation relationship, but there's alot of code.  I'm wondering if anyone knows of any tools (or even simple refactoring techniques) to aid me.  I can do it manually, it will just take me a long time.
    Note: during this conversion I will not be switching the stuff over to C++ types (i.e. std::list<xyz*> instead of struct xyz**).  That will be done later, so in all honesty I only need C refactoring tools....

    Hmmm, yeah I guess I could collect code and things, but what I'd like to do, is take a struct, along with related prototypes into one header file, and cram the implementations on the function in a related file.  Bascially I'm trying to save myself a few days of random... "ok this is a XYZ function, copy, paste in xyh.c and xyz.h, delete from original"
    There should be refactoring tools out there to do something similar... maybe I'll check the vim scripts...

  • How to run netbeans swing code without netbeans

    hi
    i created a GUI use netbeans and it compiles and runs under netbeans. my question is how can i run it on a machine doesnt have netbeans. i realise that in the netbeans project scr file, there s two .java file, but have no idea how should run it. i tried to do
    javac <GUI class name>.java
    but got lots of erro like this:
    GUI_main.java:545: package org.jdesktop.layout does not exist
    jPanel20Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    how can i do it corectly???
    dav

    Hai,
    u need to search the Classes ur using in netbeans installation directory
    i.e., org.jdesktop.layout some class.
    May i know y ur using org.jdesktop.layout package
    From where u got GroupLayout. Search GroupLayout.class and set the classpath.
    javac -classpath <path of the class files>
    regards,
    RdRose.

  • Code from swing tutorial

    hi this is code from sun's swing tutorial (http://java.sun.com/docs/books/tutorial/uiswing/learn/example1.html )
    import javax.swing.*;       
    public class HelloWorldSwing
    private static void createAndShowGUI()    // why it is private ??
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame frame = new JFrame("HelloWorldSwing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JLabel label = new JLabel("Hello World");
            frame.getContentPane().add(label);
            frame.pack();
            frame.setVisible(true);
       public static void main(String[] args) {
                 javax.swing.SwingUtilities.invokeLater(new Runnable()  // what does this snippet doing ?
                public void run()
                    createAndShowGUI();
    }i have question on this code. i have put my question in the comment . in the tutorial they are advising to " Be thread safe ...what it means ?
    can anybody explain my questions ( commentation + bold letter) ?
    thanks

    i have seen swing codes which dont use threads
    like above . does it mean they are not safe ?
    what do you mean by safe ? ...does it mean program
    can crash at any time if i dont include that
    snippet ? will you be explicit in a simpler way.It is extremely unlikely that doing the following is unsafe:
    //in main thread:
    frame.pack();
    frame.setVisible(true); //unsafe?But there's no guarantee! And by unsafe, the authors mean that undefined behavior can result --
    your GUI could do anything it wanted! That being said, it's extremely unlikely that anything bad
    would result in this example -- it's too simple. I do remember someone posting once that they
    finally tracked an intermittent bug in their app to just this!
    What I do, if I'm being safe/paranoid is call a utility method I've written, instead of calling setVisible
    in the above code:
    public static void postVisible(final JFrame f, final boolean state) {
        Runnable r = new Runnable() {
            public void run() {
                f.setVisible(state);
        SwingUtilities.invokeLater(r);
    }Problem solved!
    >
    second question was why the method was private
    static......why not public static ?(if you really
    want to make it static !!)1. Since they never instantiate HelloWorldSwing, the method had better be static.
    2. Methods should have the most restrictive scope possible. Since this is the "main" class
    that launches its own GUI, no other class needs to see createAndShowGUI, so it is private.

  • Hand made or generated GUI code, what do proffesional use?

    Hello!
    I am currious about what programs people that work as a programmer use? Is it common that they use programs that generats code like Netbeens for instance? I tryed that program in design mode to make a gui, but when I looked at the code it had generated I could not understand it. When I have seen simple example of gui code that has been hand written I have no trouble to understand the code.
    My opinion is that code is something that others than yourself can read and understand. Wich ofcource is not as simple as it sounds :) The reason I could not understand Netbeens generated code can ofcource be that I am a java beginner.
    So, what I am asking is that:
    1. Is it common that proffesional programmers use programs like Netbeens to generate GUI code ?
    2. The problem that others cant read or understand the code, is it more common that the programmer have used generated code or does the problem as easly occur when the code is hand written?
    Regards
    Martin
    Edited by: onslow77 on Nov 4, 2009 8:02 AM

    gimbal2 wrote:
    but I prefer hand made code; that generated crap is unreadable (all imho of course) and I don't understand it eitherSeconded. Code generation not only creates messy, undocumented code, but it also leads to hidden mistakes which are the worst kind. I'd rather spend a little more time writing the stuff by hand and not only having full control over the outcome, but also have full knowledge of its inner workings.Thirded. For my money, if you're building rich GUIs that are anything other than trivial, it's probably worth investing some effort in writing a layer of code to simplify building those GUIs. Working with vast amounts of raw Swing, for example, is a painful experience. For our Swing products, we've got a whole library of controls we built specific to our apps. We also wrote a layer of abstraction over the whole of Swing itself, but that's another story. Another alternative is to use a Rich Client Platform like Eclipse RCP, which provides a lot of common, rich components, and a framework for deploying them in, out of the box. Both the Eclipse and NetBeans IDEs are built upon their own respective RCP packages, which are available for you to use for your own apps. All those nice editors, drag-n-drop views, trees, menus, shortcuts and what-not, all just there for you to use without having to write any tiresome window-resizing code. Lovely. I don't know about IntelliJ, but I wouldn't be surprised if it, too, did so. Spring RCP is another such package.

  • Javaw does not work for my SWING application

    Dear all,
    I try to use 'javaw ClassName' (from a batch test.bat) to hide command prompt window when a Swing application starts. Unfortunately, the CMD still appears. So I recommend the command java and javaw has no difference in my situation.
    I use jdk1.6.0_02 runs on Windows XP Prof Service Pack 2.
    Could anyone give me some hint please?
    Regards,
    Byron
    The Swing code is attached
    import java.awt.*;
    import javax.swing.*;
    public class Reminder extends JFrame
         public static void main(String[] args)
              new Reminder();
         public Reminder()
              super("Reminder");
              JDesktopPane desktop = new JDesktopPane();
    this.setContentPane(desktop);
    this.setLocation(350, 300);
    this.setSize(300, 80);
    this.setResizable(false);
    JLabel reminder = new JLabel("Do not forget delivering reports!", SwingConstants.CENTER);
    reminder.setForeground(new Color(125, 125, 220));
    reminder.setFont(new Font("SansSerif", Font.BOLD, 18));
         this.getContentPane().setLayout(new BorderLayout());
         this.getContentPane().add("Center", reminder);
         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// set frame closeable
    //     this.setExtendedState(JFrame.MAXIMIZED_BOTH);// set maximized frame
              this.setVisible(true);
    }

    Hi Andrew,
    In my case, it does not require any web server. I could not use javaws.
    There is way work around by using Runtime.exec(). The MS Windows CMD hides when I double click the start.bat file.
    File start.bat:------------------------------------------------------------------------------------
    java Test
    File Test.java:-----------------------------------
    public class Test
         public static void main(String[] args)
              try{
                   Runtime r = Runtime.getRuntime();
                   r.exec("java Reminder");
              }catch(Exception e)
                   e.printStackTrace();
    File Reminder.java has been attached in the original post.
    Regards,
    Byron

  • What's wrong with this mini-code? (Trying to draw graphics).

    Could someone please help me fix what's wrong the following test-program?:
    package project;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class GraphicsTester extends JPanel
        JPanel thePanel = this;
        public void GraphicsTester()
            JFrame frame = new JFrame();
            frame.setSize(600,600);
            frame.add(thePanel);
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            g.drawRect(50, 50, 50, 50);
            System.out.println("Sup fool");
        public static void main(String[] args)
            GraphicsTester gt = new GraphicsTester();
            System.out.println("works2");
    }Any help would be greatly appreciated!
    Thanks in advance!

    Also, all Swing code should be called from the Event Dispatch Thread. It probably isn't hurting much in your case. But, in the body of main, do this (instead of the comment, put what you currently have as the body of main):
    EventQueue.invokeLater(
    new Runnable()
          public void run()
              // Your current body of main.
      });

  • Multi-tier Swing Application

    Hi,
    I'm currently in the planning stages of an application that will use swing, be deployed on a Websphere Application Express V5 server, and access a postgresql database. The application will need to display/add/modify data as well as do complex calculations, validations, etc. All database requests need to be made from the application server rather than the client. I'm having trouble figuring out what approach to take. I'm reading up on Swing, but what do I need to use to handle the data. Ejb's are not supported on our application server. Should I use RMI, servlets, or javabeans or a combination. Is there anything else I should consider. Any help would be appreciated. Thank you.

    You seem determined to use Swing.
    I am not sure that it is necessarily a good idea. Yes Swing allows you to create a native look and feel, but what else is it giving you? If you want to do a lot of local processing such as a CAD program, then fair enough. But Swing also give you the security risk that people can view and change your Swing code as it will likely be on the client machines. This means you will have to consider how to protect passwords.
    A servlet could communicate with Swing but is more usually in communication with a browser. This seems a little more secure. You will be able to design forms similar to the sun forum and display data. Also because the code is on the server, you can update everyones code easily.
    However if this is your first big project, you should buy in some experience, as suggested previously.

  • Help! how can I update JDK from 1.3 to 1.4 for Java Swing correctly?

    Urgent! currently I meet one trouble for GUI display, which is developed by Java Swing when I update my JDK1.3 to 1.4. I use JRun as web server and all of the GUI Java Swing code developed based on JDK 1.3 and before I update, all of the GUI display is correct and there are no problem, but after I update to JDK 1.4, I always meet this kind of problem "java.lang NoClassDefFoundError" which is displaye on Java Console and "Exception:java.lang.NullPintException" is displayed on GUI. Sometimes, I need to try two times to display GUI(Jave Swing), then it can work. Could you give me a fever and show me how to fix this problems? which kind of change in JDK Java Swing package?
    Thank you much.
    Steven

    I have recompiled app. by JDK1.4 and I also changed classpath but I can not fix the problem. The strange thing is that I can view the The same GUI(Java Swing) which is installed in another computer using the same JRUN too, but in local computer I can not view the GUI. Do you have some other suggestions? Why Can I view the same GUI instaaled in another computer?
    Very Thanks
    Steven

Maybe you are looking for

  • Balancing field "Profit Center" in line item 001 not filled

    When i am doing Posting with clearing(FB05) i am getting the below error message "Balancing field "Profit Center" in line item 001 not filled" Background: When we are doing the MIRO transaction we have used a diffrent profit center than it came from

  • CUA - Printouts

    We use CUA from our SOLMAN in a R/3 4.7 environment. During a workday we get printouts of a 2 page report. The reports are printet automatically (more than 50 a day..). 1. page: User, Host, Class 2. page:IDOC nr, USERCLONE, Serie-Info, ST, Descriptio

  • Cisco 1140AP using WPA2-enterprise with radius

    All, I am trying to configure an1140 AP to use WPA2-enterprise & radius. Ultimately I want to be able to connect to the SSID using my active directory credentials. I would like the AP to send authentication requests to our Network Policy Server. Here

  • Coodinating Colors in Multi-Camera Shoots

    I sometimes use three video cameras on a shoot: a Canon 5D II, 5D III and Sony HXR NX5U.  I white balance each camera at the exact same spot and same lighting conditions immediately before the shoot.  The video clips that are subsequently produced do

  • Can't change media type

    Any one know how to change the media type of a file? I went to "get info" like I used to but it is all gray and won't let me change it. I just got a new computer that runs windows 7 (I used to have an XP) but I don't think that should be the problem