A new AWT/Swing?

I have a question for the community.
IMHO, and I am not alone, AWT/Swing have major flaws that really ought to be fixed. Probably, because the APIs themselves are seriously flawed, what is required is a replacement for Swing.
How would one go about proposing such a thing and getting Sun's support?
Specific issues:
1) A set of specific design rules should be codified, which all conforming components, layout managers, UIs, etc., should obey. Along with the rules, there should be automated tests, so that it could be confirmed whether components, layout managers, UIs, etc., work correctly.
Currently, Swing and 3rd party components often do not work well together, for reasons such as
a) Highly irrational behavior of layout managers. Currently, none of the AWT/Swing layout managers behave in a reasonable way under all circumstances, with the possible exception of BorderLayout. Also, layout managers use constraints in inconsistent ways, and they are ill-suited to control by GUI builders.
b) Failure to use minimumSize, preferredSize, and size consistently.
c) Inconsistent use of UIs. What is the division of responsibility between the UI, layout managers, L&F, and the main class(es)?
2) Software design rules. For example, there is currently at least one Swing class that alters its behavior depending on which container it is placed in. That violates basic principles of OO development. Perusing the AWT/Swing source code, you will find plenty of objectional coding practices. It seems that the pressure to maintain backwards compatibility has been a real impediment to "doing things right".
3) Performance. AWT/Swing are notorious for various performance problems, including
a) Non-linear CPU cost associated with building certain graphical data structures (combo-boxes, for one).
b) Layout managers that call getMinimumSize or getPreferredSize on child components multiple times. Currently, the layout managers are the CPU bottleneck in many AWT/Swing GUIs.
c) Some text components are almost unbelievably slow. Try scrolling a lot of text through a JTextArea and you will be disappointed.
d) The current validation logic is extremely complex, inefficient, and undocumented. I count approximately 15 basic API methods that affect how and when components are repainted. I defy ANYONE to explain how it all works. The typical result is that repaints occur FAR more often than is necessary.
A lot of optimization is required to fix these problems. That means automating tests, profiling, removing extra repaints, CPU bottlenecks, etc.
4) Excessive complexity of the APIs. For example, it seems that building practical tables and trees is harder than it should be. The APIs are complex and documentation obscure or lacking in detail. Also, the separation between model and view is often tainted. It shouldn't be necessary to do so much conversion between model and view indices, for example. A basic set of model classes should be shared by all components that use underlying data models. These model classes should support standard functionality such as filtering, sorting, etc.
5) No portable remote operation. Yes, I am familiar with SAWT (slow and buggy), and the possibility of using X11 remotely when the Java application is run on a *nix platform (slow over a high-latency network such as the Internet and unusable on Windows systems).  There does not seem to be a usable, universal solution.
Yes, I am familiar with SWT. However, for a variety of reasons, I believe that the AWT approach is superior. SWT is more platform dependent and it has the X11 reverse-object-orientation in which child classes know about their parents. I have done some performance testing, which suggests that
1) SWT layout managers are faster than their corresponding AWT/Swing managers
2) Most other graphics, including 2D graphics, are faster in AWT/Swing than SWT.
I am sure that SWT encapsulates some good ideas. However, it seems that if the efficiency of validation and layouts could be improved, then AWT/Swing performance would be excellent, while maintaining OO and platform-independent characteristics.
Possibly, these issues could be worked out piecemeal. For example, a new, rational set of layout managers could be developed entirely independently.
Other issues, such as defining how UIs, L&F, and component classes should be architected, are going to be more problematic. Creating order in the current chaos will be difficult.
Any ideas?

>
How would one go about proposing such a thing and
getting Sun's support?
As for proposing such a thing, you can always become a member of the Java Community Process Program (it's free for individual members): http://www.jcp.org/en/home/index. As a member you can post a Java Specification Request with your suggestions. If you want to operate on a smaller scale you can report bugs to the bug database.
As for getting Sun's support....well, good luck! :-)

Similar Messages

  • New: awt is covering my swing component...

    i am using both awt and swing component on the same page. They are a List and a JComboBox.
    while the JcomboBox is placed above the List. it works fine but when i click on the JComboBox, the pull down menu is covered by the awt List. I know that using JList can solve the problem, but i'm new to swing and i just want to make the smallest change to my code.
    can i use layeredpane to help?

    here is a link to the Swing tutorial that mentions this problem:
    http://java.sun.com/docs/books/tutorial/uiswing/start/swingIntro.html#awt
    The Swing tutorial also has a section on converting from AWT to Swing. You should look at that.
    Here is another article from the Swing Connection titled "Mixing Heavy and Light Components"
    http://java.sun.com/products/jfc/tsc/articles/mixing/index.html
    Like the previous post says, you are better off not to mix the two.

  • New to swing :( need help with simple text areas

    i'm trying to make a username and pasword GUI thingy (techinical word) but what i have now is this:-
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.URL;
    import java.io.IOException;
    public class swing1 extends JFrame implements ActionListener
         private String newline = "\n";
         protected static final String textFieldString = "JTextField";
         protected static final String passwordFieldString = "JPasswordField";
         protected JLabel actionLabel;
         private JTextField textField;
         private JPasswordField passwordField;
         private Container p; // make a panel to witch the components can be added
         public swing1()
              super("swing1");
              //Create a regular text field.
              textField = new JTextField(10);
              textField.setActionCommand(textFieldString);
              textField.addActionListener(this);
              //Create a password field.
              passwordField = new JPasswordField(10);
              passwordField.setActionCommand(passwordFieldString);
              passwordField.addActionListener(this);
              //Create some labels for the fields.
              JLabel textFieldLabel = new JLabel(textFieldString + ": ");
              textFieldLabel.setLabelFor(textField);
              JLabel passwordFieldLabel = new JLabel(passwordFieldString + ": ");
              passwordFieldLabel.setLabelFor(passwordField);
              //Create a label to put messages during an action event.
              actionLabel = new JLabel("Type text and then Return in a field.");
              actionLabel.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
              //Lay out the text controls and the labels.
              p=getContentPane(); //get te contant pane of this Swing1 to add the componets to
              p.add("West",textField); //add your fist component, add it west on the dafault borderLayout
              p.add("East",textFieldLabel);// add another component, add it east on the dafault borderLayout
              p.add("South",passwordField);// add it south on the dafault borderLayout
              p.add("North",actionLabel); // add it north on the dafault borderLayout
              setSize(400,100); //make it a bit bigger
              setVisible(true);
              public void actionPerformed(ActionEvent e)
                   Object o = e.getSource();// the component that fired this event
                   if (o == textField)
                        //action from the textField
                   else if (o == passwordField)
                        //action from passwordfield
              public static void main(String[] args)
                                  JFrame frame = new TextSamplerDemo();
                                  frame.addWindowListener(new WindowAdapter()
                                       public void windowClosing(WindowEvent e)
                                                 System.exit(0);
                                                                new swing1(); //make a new instance of your class
    [\code]
    why won't the label on my password field dislay?
    and can you take a look at the end of my code i got it off another program, i want to get rid of the HTML page its trying to access and i want it just to close when i click X
    any help would be briliant
    Ant                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Since you are new to Swing the first thing I would recommend is to read the tutorial "Creating a Gui with JFC/Swing". I think the Text Component section has a demo on creating a username/password GUI. It can be downloaded at:
    http://java.sun.com/docs/books/tutorial/
    Why doesn't the password field label display? You are not adding it to the container. You add textField, textFieldLabel, passwordField, actionLabel but no passwordFieldLabel.
    Instead of adding a WindowListener and implementing the windowClosing() method, there is an easier way to close the JFrame in JDK1.3. Simply use:
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    The class "TextSamplerDemo" doesn't belong in this class (it must be a demo class you downloaded from somewhere). All the code you need in the main method is:
    JFrame frame = new swing1();
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    Also, by convention classes should be named with the first character of each word capitalized. So you class should be renamed to "Swing1" from "swing1". Also remember to rename the file as the filename and class name must be the same and case does matter.

  • Difference between AWT,Swing and swt

    Hello,
    I am giving a seminar about swing in which I need to point out differences between AWT,Swing and SWT(Software Widget Tool).
    I have two questions:
    1)I read that-A heavyweight component is one that is associated with its own native screen resource (commonly known as a peer). A lightweight component is one that "borrows" the screen resource of an ancestor-which makes it lighter.Can anybody explain What native screen resource is and how it is borrowed?
    2)I read that SWT uses native widgets and how can it be better than swing?If it is in what way?

    Use Swing for new projects. AWT is the rendering layer underneath Swing in many cases, and AWT provides utility things like Graphics. SWT is an alternative to Swing which used more native rendering, but actually with Java 6, Swing is using a lot of native rendering.
    Fire up NetBeans and use Matisse. Build an application. Run it under Windows, and then under Linux, and then realize how great it is.

  • Tutorial on AWT/Swing control flow

    Greetings all,
    Just wondering if any of you folks know of a good tutorial on AWT/Swing control flow? I'm doing some pretty complex stuff with a table whose editors call other windows and insert values into the table based on callback objects...weird stuff happening with loss of focus when the other windows come out, etc etc etc.
    I have it working via a series of what I consider kludges, but I would really like to implement it cleanly, and it's looking like that's going to require understanding <ugh> <grin>
    So it looks like it's time that I bit the bullet and got to grips with control flow in AWT/Swing. Is there a tutorial out there that could help me with this?
    Many TIA

    skiaddict1 wrote:
    Let's take your word for it, but if you have the slightest doubt please consider the subject: EDT violation is a classic here.OK sure, but I really don't think I'm violating it. I avoid multi-threading like the plague, and only introduced it for my report writer because I wanted to have a little window advising the user that the report was in the process of being written.Raise your left hand and swear this report writer is not running when you experience the problem you describe! >o(
    OK, this is just kidding, as per the rest of your description, it sounds reasonable now to assume that your problem is not related to EDT violation.
    I'm doing some pretty complex stuff with a table whose editors call other windows and insert values into the table based on callback objects...This summary is a bit worrying, and I thought you would mention problems in the display of the table being edited. But you seem to refer to problems in other windows, or did I misunderstand?
    Or do you mean, loss of focus in the editor still being edited? Can you please clarify what you do and what your problems are?
    In particular, what does the other windows come out mean?OK, I was trying to be sparse with details because I didn't think they were relevant.Actually the worrying seems all the more justified, now that you have described it more extensively: I was afraid that you would raise other windows while editing, and that's the case. I know little of focus though...
    I have a table in window A, one of whose columns has a custom editor which, when a cell in the column is double-clicked, registers itself with window B as a choice-listener (see later) then asks window B to come to the front. Window B, when the user performs a choice amongst the UI elements in there, fires a choice-event to its listener, i.e. the custom editor. At which point the editor saves away the chosen value (for use by getCellEditorValue()), sets the text in the cell appropriately, turns edit mode off via fireEditStopped(), and brings window A back to the front.
    (...) once the custom editor asks window B to come to the front, the table in window A loses focus and when it is brought back to the front, the table's JScrollPane seems to have the focus (visually, it has the focus rectangle around it). Pressing the Tab key has no effect on focus; you have to use the mouse to focus something.I assume you have read the tutorial on using tables in Swing.
    It contains an example where a custom editor is bringing up a dialog: http://download.oracle.com/javase/tutorial/uiswing/components/table.html#editor
    AFAIK, the example does not suffer from focus problems.
    What I am finding, and I reiterate this is new since I rewrote the windowing subsystem for the app (the custom editor was not changed in the rewrite), is that (...)Just what do you call "rewriting the windowing system" (just to rule out the possibility of something Ramboesque)?
    I have no idea why this loss of focus is occurring, and I am at a loss to begin to figure it out. As I wrote above, I have a series of kludges which gets around the symptoms, but I would really rather figure it out and fix it.OK I admit I cannot tell what happens exactly, but:
    1) instead of bringing window B to front, couldn't the editor bring up a dialog B (e.g. using JOptionPane.showXxxDialog() to bring up just the choice panel? The advantage is that it is more "synchronous", you can control when the window A's table model is updated.
    2) what worries me too is that you update the model of the table being edited while you're editing one cell of it? Would it be possible, and make sense in your case, to update this model later (that is, post the model update as an invokeLater(...) call)? I don't see how seeing the table updating underneath helps the user editing its cell, but you may have your reasons.
    What do you call flow control , or control flow in AWT/Swing?Basically, what I am after is something that will help me begin to understand/diagnose problems such as the above when they happen in my code. I am deeply averse to multi-threading (...) Things in my code were working, and that was enough for me.
    But the above behaviour, and another weird behaviour I was having last week, which again I have solved with what I consider a kludge, and again which only began with my new windowing subsystem, have caused me to realise that it's time I really got to grips with this issue.Yes, when they say beware of threads when using Swing , nobody tells to not use threads! Just to be aware of how special Swing is with regards to threads (at least, compared to AWT, that didn't make such warning).
    I would like, for example, to really deep-down understand exactly when listeners for AWT-Swing events get called. I don't really care so much when the events get put on the queue, but I do care when exactly my event handlers will be called. This will help me diagnose problems, I'm sure.Well they get called in the EDT, by some framework code that, in an infinite loop, does something along the lines of:
    - pop next event from the event queue
    - determine which is the target widget
    - let the widget transform the event and send it to all registered listeners
    Now with dialogs, things gets dimmer, because while a dialog is brought up (via a<tt>setVisible(true)</TT> call on the EDT, the EDT is indeed suspended, and a new event thread manages the events for the dialog).
    I'm sorry I have no reference for that behavior, and my description is certainly blurry (and possibly wrong), but I don't think your problem is so much related to threading as I initially thought.
    N.B.: Darryl's second link does features sequence diagrams that try to demonstrate what happen (in a specific example with asynchronous access, but you can derive the simpler, regular, working, from it).OK, yes I saw that diagram, I was offput by the asynchronicity but I will have another look tomorrow also. Thanks againDon't put too much hopes in there, indeed it's definitely not the kind of info I understand you're looking after.
    Much luck all the same, and feel free to come back with your findings, or with more questions, about the initial subject (reference on event flow) and the specific problem (your focus issues with the editor).
    I also cannot end this message without suggesting that you try to reproduce the problem with an SSCCE (http://sscce.org), that you could post here for us to try out. See this recent discussion about the multiple interests of this approach: {message:id=9587964}
    Best regards,
    J.

  • AWT/Swing gui flickering

    I am trying to add the swing JDesktopPane to java.awt.Frame .The JDesktopPane includes
    JInternalFrame.The problem is that the GUI is flickering when resized or moved.
    I migrated from jre1.4 to jre1.5 and the flickering of the JDesktopPane stops but the
    JInternalFrame is still flickering when resized/moved.I am wondering if at this point
    this is a AWT/Swing issue.

    Never ever mix AWT and Swing!At least not their components. :p ;)

  • Awt swing 1.1

    Hi,
    Where can I actually download AWT swing 1.1 package to run with jdk 1.1.?

    http://java.sun.com/products/archive/jfc/1.1.1/index.html

  • New to swing: Error while using getText() in ActionPerformed

    Hi there!
    I'm fairly new to java and swing, and this problem I'm having drives me nuts!
    // Imports //
    public class Generator extends JFrame {
         // Graphical components
         private JTextField nr1;
         private JTextField nr2;
         // Constructor
         public Generator() {
              // Call superclass
                    // Init variables
              JTextField nr1 = new JTextField(2);
              JTextField nr2 = new JTextField(2);
              nr1.setVisible(true);
              nr2.setVisible(true);
              // Layout stuff..
              // Create listner-object for event handeling
              Lyssnare minLyssnare = new Lyssnare();
              playerName.addActionListener(minLyssnare);
              clear.addActionListener(minLyssnare);
              shuffle.addActionListener(minLyssnare);
              // closing of window
              // Pack
              // Visible
         // Action Listener
         class Lyssnare implements ActionListener {
              public void actionPerformed(ActionEvent ae) {
                   // Some other actions...
                            // Shuffle
                   else if(ae.getSource() == shuffle) {
                        String teams = nr1.getText();
                        String players = nr2.getText();
                        Shuffle.shuffle(name);
                        playerArea.setVisible(false);
                        int teamsint = Integer.parseInt(teams);
                        int playersint = Integer.parseInt(players);
                        error1.setVisible(true);
         }The error I get is after "else if(ae.getSource() == shuffle) {"
    something on the next line (and the line after that) is the one who gives the error...
    I Get this (during running, compile works fine..):
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    AFAIK that means I'm reffering to something that is null... but how can that be when all the textfields are initialised? do I have to make does fields global in some way?
    Grateful for any help!

    Your inner class does not have access to nr1 and nr2 because they are not final variables.
    Instead of creating an inner class Lyssnare, you can have your Generator class implement the ActionListener and add the actionPerformed method inside Generator class as follows:
    public class Generator extends JFrame implements ActionListener {
         // Graphical components
         private JTextField nr1;
         private JTextField nr2;
         // Constructor
         public Generator() {
              // Call superclass
                    // Init variables
              JTextField nr1 = new JTextField(2);
              JTextField nr2 = new JTextField(2);
              nr1.setVisible(true);
              nr2.setVisible(true);
              // Layout stuff..
              // Create listner-object for event handeling
              //Lyssnare minLyssnare = new Lyssnare();
              playerName.addActionListener(this);
              clear.addActionListener(this);
              shuffle.addActionListener(this);
              // closing of window
              // Pack
              // Visible
    public void actionPerformed(ActionEvent ae) {
                   // Some other actions...
                            // Shuffle
                   else if(ae.getSource() == shuffle) {
                        String teams = nr1.getText();
                        String players = nr2.getText();
                        Shuffle.shuffle(name);
                        playerArea.setVisible(false);
                        int teamsint = Integer.parseInt(teams);
                        int playersint = Integer.parseInt(players);
                        error1.setVisible(true);
              }

  • Create New Awt Component

    Is it possible, and if it is, how can I create completely new gui component using awt?

    Sure. Just extend Component and override the paint method to draw it the way you want. Add a mouse listener to capture clicks or drags and do whatever you want with those, etc. I create new Swing components with special behavior all the time. (I don't think I've ever done one in pure AWT, but the principle is the same.) My variations tend to be trivial, like labels with text that wraps to the available space instead of a single line, not stuff that is going to set the computer world on fire. Depening on how complex the new component you want to invent is, this might be far from a trivial task. But it's certainly do-able.

  • TCL/Tk- Awt- Swing

    This is my first Java code. I am attempting to use Java for an applet
    that was originally in TCL/Tk. My first pass used just Awt. Now I have
    a Swing version.
    Linux 2.4.8-26mdk
    java version "1.4.0_02"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_02-b02)
    Java HotSpot(TM) Client VM (build 1.4.0_02-b02, mixed mode)
    appletviewer
    The Awt version works as I expect. The Swing version also works as
    expected except that the filled arc does not display correctly when
    the arc to be displayed is smaller than the previous one.
    AwtCircle.java:
    package org.emle.equipment;
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    public class AwtCircle extends Applet
      private int fractionDenominator;
      private double decimalValue;
      private Button dButtons[] = new Button[9];
      public void init ()
        fractionDenominator = 4;
        decimalValue = 1.0 / (double)fractionDenominator;
        Box dBox = Box.createHorizontalBox();
        for (int ii=2; ii<=8; ii++)
          dButtons[ii] = new Button("1/" + ii);
          dBox.add(dButtons[ii]);
        } this.add(dBox);
      public void paint(Graphics argG)
        argG.setColor(Color.white);
        argG.fillRect(0, 0, 500, 500);
        argG.setColor(Color.lightGray);
        argG.fillArc(100, 50, 100, 100, 0, (int)(decimalValue * 360.0));
      public boolean action(Event argE, Object argO)
        for (int ii=2; ii <= 8; ii++)
          if (argE.target == dButtons[ii])
            fractionDenominator = ii;
        decimalValue = 1.0 / (double)fractionDenominator;
        showStatus("1/" + fractionDenominator);
        paint (getGraphics());
        return true;
    SwingCircle.java:
    package org.emle.equipment;
    public class SwingCircle extends javax.swing.JApplet
      implements java.awt.event.ActionListener
      private int fractionDenominator;
      private double decimalValue;
      private java.awt.Button dButtons[] = new java.awt.Button[9];
      public void init ()
        fractionDenominator = 4;
        decimalValue = 1.0 / (double)fractionDenominator;
        javax.swing.Box dBox = javax.swing.Box.createHorizontalBox();
        for (int ii=2; ii<=8; ii++)
          dButtons[ii] = new java.awt.Button("1/" + ii);
          dBox.add(dButtons[ii]);
          dButtons[ii].addActionListener(this);
        } getContentPane().add(dBox,java.awt.BorderLayout.SOUTH);
      public void paint(java.awt.Graphics argG)
        argG.setColor(java.awt.Color.white);
        argG.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
        argG.setColor(java.awt.Color.lightGray);
        argG.fillArc(100, 50, 100, 100, 0, (int)(decimalValue * 360.0));
        dButtons[fractionDenominator].requestFocus();
      public void actionPerformed(java.awt.event.ActionEvent argE)
        String cmd = argE.getActionCommand();
        for (int ii=2; ii <= 8; ii++)
          if (dButtons[ii].getActionCommand().equals(cmd))
            fractionDenominator = ii;
        decimalValue = 1.0 / (double)fractionDenominator;
        showStatus("1/" + fractionDenominator);
        paint(getGraphics());
        return;
    C.W.Holeman II
    [email protected] http://MistyMountain.org/~cwhii
    Remove the fives Send spam to [email protected]

    Cimi has made tcl/tk-cvs packages.
    http://bbs.archlinux.org/viewtopic.php? … light=cimi

  • AWT/Swing difference Component.paint(Graphics g)

    In the following code, I try to paint some component into a VolatileImage, also tried with BufferedImage, and draw the Image on some other component. Anyways it works with java.awt.Panel doesn't with JPanel, does anyone have a clue why?
    Differences between Graphics and Graphics2D maybe?
    package sqltest;
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class AWTVC extends java.awt.Panel {
        public AWTVC(Component c) {
            this.c = c;
            //initComponents();
            Thread t = new Thread(){
                public void run(){
                    try{
                    Thread.sleep(2000);
                    bu=createVolatileImage(500,500);
                    while(true){
                        AWTVC.this.c.paint(bu.createGraphics());
                        getComponent(0).paint(bu.createGraphics());
                        AWTVC.this.repaint();
                        Thread.sleep(80);
                    }catch(Exception e){
                        e.printStackTrace();
            t.start();
            initComponents();
        private void initComponents() {
            setLayout(new java.awt.BorderLayout());
            addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentResized(java.awt.event.ComponentEvent evt) {
                    formComponentResized(evt);
        private void formComponentResized(java.awt.event.ComponentEvent evt) {
            bu=createVolatileImage(getWidth(), getHeight());
        final Component c;
        VolatileImage bu=null;
        public void update(Graphics g){
            g.drawImage(bu,0,0,getWidth(),getHeight(),null);
    }Any help would be greatly appreciated!
    Cheers

    Well thanx alot,
    Well I just asked out of curiosity, it works perfectly with the LIGHTWEIGHT_RENDERER, I was just curious to know why AWT components won't draw into Graphics2D (That seemed to be the problem). Well It works now so it doesn't really matter. Well I think the HeavyWeight Renderer is hardware accelerated, maybe that's the reason. Also since I'm using jdk 1.5 do you think setting the -Dsun.java2d.opengl=true property will improve performance. I have cpu cycles to spare, so I can't see the difference ;-)

  • Help needed new to Swing Programming

    Hi,
    I have Crated a JFrame (Frame1) with 4 textfields and a button (by name GetBarchart).
    My question is i will enter some values in 4 textfields and press the GetBarchart button it should display a new JFrame( say Frame2 ) and a Barchart with values taken form the 4 textfields should be displyed.
    NOTE: I should get the BarChart displayed in Frame2 , NOT in Frame1.
    anyhelp is appeciated .
    Thanks in advance

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;
    import org.jfree.chart.*;
    import org.jfree.chart.plot.*;
    import org.jfree.data.category.*;
    import org.jfree.ui.*;
    // Make a main window with a top-level menu: File
    public class MainWindow extends JFrame {
        public MainWindow() {
            super("Menu System Test Window");
            setSize(500, 500);
            // make a top level File menu
            FileMenu fileMenu = new FileMenu(this);
            // make a menu bar for this frame
            // and add top level menus File and Menu
            JMenuBar mb = new JMenuBar();
            mb.add(fileMenu);
            setJMenuBar(mb);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    exit();
        public void exit() {
            setVisible(false); // hide the JFrame
            dispose(); // tell windowing system to free resources
            System.exit(0); // exit
        public static void main(String args[]) {
            MainWindow w = new MainWindow();
            w.setVisible(true);
        private static MainWindow w ;
        protected JTextField t1, t2, t3, t4;
        // Encapsulate the look and behavior of the File menu
        class FileMenu extends JMenu implements ActionListener {
            private MainWindow mw; // who owns us?
            private JMenuItem itmPE   = new JMenuItem("ProductEvaluation");
            private JMenuItem itmExit = new JMenuItem("Exit");
            public FileMenu(MainWindow main) {
                super("File");
                this.mw = main;
                this.itmPE.addActionListener(this);
                this.itmExit.addActionListener(this);
                this.add(this.itmPE);
                this.add(this.itmExit);
            // respond to the Exit menu choice
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == this.itmPE) {
                    JFrame f1 = new JFrame("ProductMeasurementEvaluationTool");
                    f1.setSize(1290,1290);
                    f1.setLayout(null);
                    t1 = new JTextField("0");
                    t1.setBounds(230, 630, 50, 24);
                    f1.add(t1);
                    t2 = new JTextField("0");
                    t2.setBounds(430, 630, 50, 24);
                    f1.add(t2);
                    t3 = new JTextField("0");
                    t3.setBounds(630, 630, 50, 24);
                    f1.add(t3);
                    t4 = new JTextField("0");
                    t4.setBounds(840, 630, 50, 24);
                    f1.add(t4);
                    JLabel l1 = new JLabel("Select the appropriate metrics for Measurement Process Evaluation");
                    l1.setBounds(380, 50, 380, 20);
                    f1.add(l1);
                    JLabel l2 = new JLabel("Architecture Metrics");
                    l2.setBounds(170, 100, 110, 20);
                    f1.add(l2);
                    JLabel l3 = new JLabel("RunTime Metrics");
                    l3.setBounds(500, 100, 110, 20);
                    f1.add(l3);
                    JLabel l4 = new JLabel("Documentation Metrics");
                    l4.setBounds(840, 100, 130, 20);
                    f1.add(l4);
                    JRadioButton rb1 = new JRadioButton("Componenent Metrics",false);
                    rb1.setBounds(190, 140, 133, 20);
                    f1.add(rb1);
                    JRadioButton rb2 = new JRadioButton("Task Metrics",false);
                    rb2.setBounds(540, 140, 95, 20);
                    f1.add(rb2);
                    JRadioButton rb3 = new JRadioButton("Manual Metrics",false);
                    rb3.setBounds(870, 140, 108, 20);
                    f1.add(rb3);
                    JRadioButton rb4 = new JRadioButton("Configuration Metrics",false);
                    rb4.setBounds(190, 270, 142, 20);
                    f1.add(rb4);
                    JRadioButton rb6 = new JRadioButton("DataHandling Metrics",false);
                    rb6.setBounds(540, 270, 142, 20);
                    f1.add(rb6);
                    JRadioButton rb8 = new JRadioButton("Development Metrics",false);
                    rb8.setBounds(870, 270, 141, 20);
                    f1.add(rb8);
                    JCheckBox  c10 = new JCheckBox("Size");
                    c10.setBounds(220, 170, 49, 20);
                    f1.add(c10);
                    JCheckBox c11 = new JCheckBox("Structure");
                    c11.setBounds(220, 190, 75, 20);
                    f1.add(c11);
                    JCheckBox c12 = new JCheckBox("Complexity");
                    c12.setBounds(220, 210, 86, 20);
                    f1.add(c12);
                    JCheckBox c13 = new JCheckBox("Size");
                    c13.setBounds(220, 300, 49, 20);
                    f1.add(c13);
                    JCheckBox c14 = new JCheckBox("Structure");
                    c14.setBounds(220, 320, 75, 20);
                    f1.add(c14);
                    JCheckBox c15 = new JCheckBox("Complexity");
                    c15.setBounds(220, 340, 86, 20);
                    f1.add(c15);
                    JCheckBox c19 = new JCheckBox("Size");
                    c19.setBounds(580, 170, 49, 20);
                    f1.add(c19);
                    JCheckBox c20 = new JCheckBox("Structure");
                    c20.setBounds(580, 190, 75, 20);
                    f1.add(c20);
                    JCheckBox c21 = new JCheckBox("Complexity");
                    c21.setBounds(580, 210, 86, 20);
                    f1.add(c21);
                    JCheckBox c22 = new JCheckBox("Size");
                    c22.setBounds(580, 300, 49, 20);
                    f1.add(c22);
                    JCheckBox c23 = new JCheckBox("Structure");
                    c23.setBounds(580, 320, 75, 20);
                    f1.add(c23);
                    JCheckBox c24 = new JCheckBox("Complexity");
                    c24.setBounds(580, 340, 86, 20);
                    f1.add(c24);
                    JCheckBox c28 = new JCheckBox("Size");
                    c28.setBounds(920, 170, 49, 20);
                    f1.add(c28);
                    JCheckBox c29 = new JCheckBox("Structure");
                    c29.setBounds(920, 190, 75, 20);
                    f1.add(c29);
                    JCheckBox c30 = new JCheckBox("Complexity");
                    c30.setBounds(920, 210, 86, 20);
                    f1.add(c30);
                    JCheckBox c31 = new JCheckBox("Size");
                    c31.setBounds(920, 300, 49, 20);
                    f1.add(c31);
                    JCheckBox c32 = new JCheckBox("Structure");
                    c32.setBounds(920, 320, 75, 20);
                    f1.add(c32);
                    JCheckBox c33 = new JCheckBox("Complexity");
                    c33.setBounds(920, 340, 86, 20);
                    f1.add(c33);
                    ActionListener action = new MyActionListener(f1, t1, t2,t3,t4);
                    JButton b1  = new JButton("Button1");
                    b1.setBounds(230, 600, 120, 24);
                    b1.addActionListener(action);
                    f1.add(b1);
                    JButton b2  = new JButton("Button2");
                    b2.setBounds(430, 600, 120, 24);
                    b2.addActionListener(action);
                    f1.add(b2);
                    JButton b3  = new JButton("Button3");
                    b3.setBounds(630, 600, 120, 24);
                    b3.addActionListener(action);
                    f1.add(b3);
                    JButton b4  = new JButton("Button4");
                    b4.setBounds(840, 600, 120, 24);
                    b4.addActionListener(action);
                    f1.add(b4);
                    JButton b5  = new JButton("Generatechart");
                    b5.setBounds(1040, 600, 120, 24);
                    b5.setBounds(530, 660, 120, 24);//uhrand
                    b5.addActionListener(action);
                    f1.add(b5);
                    f1.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                            System.exit(0);
                    f1.setVisible(true);
                } else {
                    mw.exit();}
        class MyActionListener implements ActionListener {
            private JFrame     f1;
            private JTextField t1;
            private JTextField t2;
            private JTextField t3;
            private JTextField t4;
            private  final DecimalFormat result = new DecimalFormat("0.0");
            public MyActionListener(JFrame f1, JTextField tf1, JTextField tf2,JTextField tf3,JTextField tf4) {
                this.f1 = f1;
                this.t1 = tf1;
                this.t2 = tf2;
                this.t3 = tf3;
                this.t4 = tf4;
            public void actionPerformed(ActionEvent e) {
                String s = e.getActionCommand();
                if (s.equals("Button1")) {
                    Component[] components = this.f1.getContentPane().getComponents();
                    int numOfCheckBoxes = 81;
                    int numChecked = 0;
                    for (int i = 0; i < components.length; i++)
                        if (components[i] instanceof JCheckBox)
                            if (((JCheckBox)components).isSelected())
    numChecked++;
    double ratio = ((double) numChecked / (double) numOfCheckBoxes)*100;
    this.t1.setText(result.format(ratio) );
    }else if (s.equals("Button2")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+5);
    this.t2.setText(result.format(ratio) );
    }else if (s.equals("Button3")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+10);
    this.t3.setText(result.format(ratio) );
    }else if (s.equals("Button4")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+15);
    this.t4.setText(result.format(ratio) );
    }else if (s.equals("Generatechart")) {
    Bar_Chart barChart = new Bar_Chart("Bar Chart", t1.getText(),t2.getText(),t3.getText(),t4.getText());
    barChart.pack();
    RefineryUtilities.centerFrameOnScreen(barChart);
    barChart.setVisible(true);
    class Bar_Chart extends JDialog {
    String t1,t2,t3,t4;
    public Bar_Chart(String title, String t1, String t2, String t3, String t4) {
    this.t1=t1;
    this.t2=t2;
    this.t3=t3;
    this.t4=t4;
    setModal(true);
    setTitle(title);
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    CategoryDataset dataset = createDataset();
    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(chartPanel);
    private CategoryDataset createDataset() {
    String series1 = "First";
    String series2 = "Second";
    String series3 = "Third";
    String series4 = "Fourth";
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(Double.parseDouble(t1.replace(',','.')), series1, "");
    dataset.addValue(Double.parseDouble(t2.replace(',','.')), series2, "");
    dataset.addValue(Double.parseDouble(t3.replace(',','.')), series3, "");
    dataset.addValue(Double.parseDouble(t4.replace(',','.')), series4, "");
    return dataset;
    private static JFreeChart createChart(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(
    "Bar Chart", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    PlotOrientation.VERTICAL, // orientation
    true, // include legend
    true, // tooltips?
    false // URLs?
    return chart;

  • AWT/Swing in JSP

    Can we use Abstract Window Toolkit(AWT) or Swing classes in JSP? If is it so, is it preferable to use those in jsp?
    Details are welcome.
    Thanks

    Yes and no. It really depends what you are talking about. There is less than no point trying to run any of the AWT windowing stuff because you are not generating a Java front end you are generating an HTML front end. Java UI components would just not work in that context- the UI would only appear on the Server, not on the client side. Unless you wrote it as an applet, at which point it has nothing to do with jsp and becomes and applet programming question.
    If you are talking about the image processing APIs then yes, I have used those and it was quite tricky because I was trying to run it on a server that did not have X windows running on it and AWT needs that to run properly.

  • Awt/swing class overview

    Hi,
    I have some questions about the general class structure of AWT and Swing:
    - How are AWT and Swing intended to work together -- should I treat AWT as an implementation detail and operate on Swing level only, or should they be used together?
    - What exactly is the purpose of the JComponent class, if there is already aws.Component?
    - Why is the GUI button class "JButton" a subclass of aws.Container? In what way is a button a container component?
    Thanks in advance.

    Hey, you really want to know all the details, do you?
    There is nothing wrong with mixing swing components and awt components, but there are some limitations.
    Read this nice article at the Swing Connection:
    http://java.sun.com/products/jfc/tsc/articles/mixing/index.html
    We need to sort some things out:
    AWT in general is not outdated.
    Swing builds on and extends AWT concepts (e.g. layout managers are part of the AWT package as is the Color class and many other features). It does not replace AWT.
    The only part of AWT that really is outdated are the heavyweight components like Button, CheckBox, ...
    All of these are replaced by lightweight Swing components (and many more components and features are added in Swing).
    Still the AWT components are frequently used in applets. That's because no browser has a recent Java version preconfigured. (Yet, If possible (like in intranet deployment) I would insist that users install recent version of Sun's Java plug-in, so that I can use swing features.)
    The only AWT components that are still used are Frame, Window and Dialog because the corresponding Swing components subclass them.
    Why do you think there is no root for components? All components subclass awt.Component and all Swing components (except for JFrame, JWindow, JDialog) subclass JComponent.
    Stephen

  • Awt swing javafx integration problem

    Hi !
    i'm trying to "merge" a swing component (an extension of a JPanel) in a personal javafx software.
    Is there any way to achieve my goal?
    Surfing the web i found only how to implement javafx in swing...
    thank you!

    solved by using thingsFx classes (new SwingView(swingComponent)) :)
    http://thingsfx.com/

Maybe you are looking for