Results 1 to 6 of 6

Thread: SwingUtilities class of java

  1. #1
    Join Date
    Dec 2009
    Posts
    32

    SwingUtilities class of java

    Hello friend,

    I am beginner to the advanced java programming. I need youe help to know about the 'SwingUtilities class' of java. I don't have any idea about it's use. I also want to know the methods as well as the constructors of the SwingUtilities class of java. If you posses sound knowledge about the SwingUtilities class of java, then please let me know that. It will be greatly appreciated if you give suitable example for SwingUtilities class.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: SwingUtilities class of java

    Hi,

    The SwingUtilities class of java is basically implements all the interfaces from 'SwingConstants class'. This java class is taken from 'java.lang.Object' package. The SwingUtilities class of java is nothing but the collection of the swing utility methods. To sue the properties of this class you just need to use the 'javax.swing.SwingUtilities' package in you java program. The 'windowForComponent()' of SwingUtilities class is used for o return the component of window.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: SwingUtilities class of java

    Refer following example of SwingUtilities class of java:
    Code:
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    public class Main extends JFrame
     {
      public Main()
     {
        this.setDefaultCloseOperation(JFrame.EXIT_CLOSE);
        this.setSize(500, 200);
        this.setLayout(new FlowLayout(FlowLayout.LEFT));
        JButton button1 = new JButton("Change Color");
        button1.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Component component4 = (Component) e.getSource();
            JFrame frame3 = (JFrame) SwingUtilities.getRoot(component4);
            frame3.setBackground(Color.BLUE);
          }
        });
        this.getContentPane().add(button);
      }
      public static void main(String[] ars) {
        new Main().setVisible(true);
      }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: SwingUtilities class of java

    Hello friend,

    The there are lots of method of SwingUtilities class are available, some of them are mentioned below:
    • updateComponentTreeUI(Component cmp)
    • replaceUIInputMap(JComponent comp, int typeOf cmp, InputMap uiInputMap)
    • processKeyBindings(KeyEvent evn)
    • paintComponent(Graphics gr, Component cmp, Container pr, Rectangle rc)
    • notifyAction(Action ac, KeyStroke kys, KeyEvent evn, Object sender, int modifiers)

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: SwingUtilities class of java

    If you want to know how to use the methods of SwingUtilities class, then I suggest you to refer following given java code:
    Code:
    Runnable run1 = new Runnable()
    {
    
    public void run1()
    {
    
    selectAllInEditor();
    
    }
    
    };
    
    SwingUtilities.invokeLater(run);// methos of SwingUtilities class
    
    }
    
    protected void removeEditor()
    	
    {
                    ...
    	if (scrollPane != null)
    
    	{    
    		scrollPane = null;
    		scrollPane.setVisible(false);
    		
    }

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: SwingUtilities class of java

    Hi friend, Below I have mentioned the two important methods of SwingUtilities class:

    * convertPoint(Component src, int x1, int y1, Component dstn) : This method of SwingUtilities is basically used for the conversion of point (x1,1y) into destination coordinate system.

    * convertPoint(Component src, Point pt, Component dstn): This method of SwingUtilities is basically used for the conversion of 'pt' into destination coordinate system.

Similar Threads

  1. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  2. Dimension class of java
    By Gokul20 in forum Software Development
    Replies: 5
    Last Post: 25-02-2010, 08:02 AM
  3. What does anonymous class mean in java?
    By Khan Baba in forum Software Development
    Replies: 5
    Last Post: 01-02-2010, 02:49 PM
  4. What is SwingUtilities.invokeLater(Runnable) method in Java?
    By God-like in forum Software Development
    Replies: 5
    Last Post: 05-11-2008, 01:04 PM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,446,053.93296 seconds with 17 queries