Make a seprate swing application

I am running a swing application that is having toolbars with different buttons. In the buttons I am having a record button that is opening a recording window. When I click on the quit button of toolbar the toolbar along with the recording window is closing. My requirement is not to close the recording window when I quit from the toolbar.
How to start seprate process from the java application. If I quit the one should not close the other process.

Please reply imm:
Assume we have 2 applications 1) App name IW 2) App name is RP
IW geneartes a toolbar which contains some buttons.
Here I can get output of RP by running itself or from a button of a toolbar which generated by running IW app.
Now here is my requirement which should follow below 3 points :
At any time I should have only single output for RP app. i.e,
1) If I run RP app , then next i clicked RP source button in toolbar of IW,
then i should get any more output of RP since it is already running( already RP output exist / at a time single instance for RP).
2) If I run IW app, then toolbar generated .Now I clicked on RP source button.I got the output of RP app by running RP app with Runtime class.
If I click one more time on RP source button , I should not get one more output for RP app, at any time I should have only single instance for RP.
I can get RP output if and only if I dont have any output of RP app on desktop.
3) If RP app run from IW , then If I try to run RP independently I should not get any more instance output for RP.
Thanks
rams

Similar Messages

  • How to give Common Background color for all JPanels in My Swing application

    Hi All,
    I am developing a swing application using The Swing Application Framework(SAF)(JSR 296). I this application i have multiple JPanel's embedded in a JTabbedPane. In this way i have three JTabbedPane embedded in a JFrame.
    Now is there any way to set a common background color for the all the JPanel's available in the application??
    I have tried using UIManager.put("Panel.background",new Color.PINK);. But it did not work.
    Also let me know if SAF has some inbuilt method or way to do this.
    Your inputs are valuable.
    Thanks in Advance,
    Nishanth.C

    It is not the fault of NetBeans' GUI builder, JPanels are opaque by default, I mean whether you use Netbeans or not.Thank you!
    I stand corrected (which is short for +"I jumped red-eyed on my feet and rushed to create an SSCCE to demonstrate that JPanels are... mmm... oh well, they are opaque by default... ;-[]"+)
    NetBeans's definitely innocent then, and indeed using it would be an advantage (ctrl-click all JPanels in a form and edit the common opaque property to false) over manually coding
    To handle this it would be better idea to make a subclass of JPanel and override isOpaque() to return false. Then use this 'Trasparent Panel' for all the panels where ever transparency is required.I beg to differ. From a design standpoint, I'd find it terrible (in the pejorative sense of the word) to design a subclass to inconsistently override a getter whereas the standard API already exposes the property (both get and set) for what it's meant: specify whether the panel is opaque.
    Leveraging this subclass would mean changing all lines where a would-be-transparent JPanel is currently instantiated, and instantiate the subclass instead.
    If you're editing all such lines anyway, you might as well change the explicit new JPanel() for a call to a factory method createTransparentJPanel(); this latter could, at the programmer's discretion, implement transparency whichever way makes the programmer's life easier (subclass if he pleases, although that makes me shudder, or simply call thePanel.setOpaque(false) before returning the panel). That way the "transparency" code is centralized in a single easy to maintain location.
    I had to read the code for that latter's UI classes to find out the keys to use (+Panel.background+, Label.foreground, etc.), as I happened to not find this info in an authoritative document - I see that you seem to know thoses keys, may I ask you where you got them from?
    One of best utilities I got from this forum, written by camickr makes getting these keys and their values very easy. You can get it from his blog [(->link)|http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/]
    Definitely. I bit a pair of knucles off when discovered it monthes after cumbersomely traversing the BasicL&F code...
    Still, it is a matter-of-fact approach (and this time I don't mean that to sound pejorative), that works if you can test the result for a given JDK version and L&F, but doesn't guarantee that these keys are there to stand - an observation, but not a specification.
    Thanks TBM for highlighting this blog entry, that's the best keys list device I have found so far, but the questions still holds as to what specifies the keys.
    Edited by: jduprez on Feb 15, 2010 10:07 AM

  • Problem with "find" mode in adf/swing application

    Hi all,
    I'm working on ADF Swing application which uses MS SQL Server 2005 (JDeveloper 10g 10.1.3)
    I think that my issue might be well-known…sorry if it has been already discussed somewhere else…
    I have a problem with the “find” mode for a detail panel in a master-detail form…(To make it clear the “find” mode is switched on when clicking on the special button on a navigation panel).
    So this mode works well in a master panel, but it demonstrates strange behavior on a detail panel, i.e. it takes me two attempts to find the necessary child object and it doesn’t switch back in a simple way from this mode to the normal mode….say if we are in the department 10 (Dept is a master form) we can’t simply find KING employee (Emp is a detail form)…is there any workaround for this?
    Thanks in advance. Alex.

    Hi Frank, please look this issue

  • Problem in Opening HTML Page in Internet Explorer from my Swing Application

    Hi,
    I am opening a HTML file in Internet Explorer from my swing application.I am using the code given below
    private final static String WIN_FLAG = "url.dll,FileProtocolHandler";
    private final static String WIN_PATH = "rundll32";
    String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
    // url is HTML file Path
    Process p = Runtime.getRuntime().exec( cmd );
    Here there are two things i need to address ...
    1)The HTML file is opening up,but it always opens behind the swing application,that makes me every time to maximize the HTML file after it being opened up.I want to open it in front of the Swing Application.I need to implement "Always On Top" functionality for the html page.
    2)Whenever i trigger action to open different HTML page,it opens in new Internet Explorer window.
    I need to open it in same IE window.
    how to solve out these problems ??? any help would be greatly appreciated .Thanks in advance.
    - Manikandan

    any idea about this ????

  • Problem while creating JAR file for my swing application

    Hi...
    Using my swings application I am trying to Run different software�s .
    My program is Running fine from command prompt. If I create JAR file
    It is giving error like �Failed to load Main-Class manifest attribute from .jar�
    Can anybody help me to creating JAR file
    Thanks in advance
    Cheers
    Mallik

    hi,
    User following command
    jar-cmf textfile_name.txt Jarfile_name *
    here you have to make manifest file
    and making jar file you have reach there by command promt
    and manifest file have some constraint also as well as format
    format are
    Manifest-Version: 1.0
    Class-path: jar file name which are using in app separed by space
    Created-By: 1.5.0 (Sun Microsystems Inc.)
    Main-Class: Main class name
    and end of file is not have carriage return

  • How can I unit test my Swing application?

    Hi All,
    In my application I came across a situation where I have to automate the unit testing of my application.
    Using my application user can able to draw polylines and rectangles on a BufferedImage added to a JFrame.
    Can any one please help/suggest me, how to automate the drawing process (this process consists of drawing the polylines with mouse and few action/mouse events)?
    your help will be highly helpful to me.
    Satya

    What exactly will that unit test prove? That you can mock the drawing of lines?
    Unit test are supposed to test certain parts of your application code - I'd concentrate on unit tests that are actually useful and for example in the future can help to catch regressions.
    If anywhere you can get help creating unit tests of this magnitude, I'd look in the unit testing support for Swing applications. Google for "java swing unit test" to see what you can come up with. Probably you'll need to create some plumbing yourself to make custom painting unit-testable; perhaps you could do something with painting to a BufferedImage in stead of to a Swing component for example.

  • Swing application eats CPU on resume after standby

    My application contains a mix of regular Swing components and about 200 (small) custom components (JPanels) that draw themselves. The problem is that if put my laptop into Standby, then restart it, the application eats CPU. It goes from ~4% pre standby to ~48% after standby. Totally repeatable. There is only the main thread, the AWT thread and a couple timers firing: one to get data from a server and one to redraw the custom controls to make the control blink (calls repaint() to cue up a call to paintComponent()). I put timing code in the two timer driven threads and both are running fine. NOTE: each of the custom components is just a rectangle with a short text string in it. Think checkerboard with text. The background color is all that is being changed. It's basically a grid of alarm/status "lights".
    I did some searching and only found a reference to a drawing bug that was fixed back in 1.4.x that had to do with WinXP and dual-headed computers.
    Note that another simple Swing application I wrote (no custom controls), doesn't appear to behave this way, so I suspect it has to do with the custom drawing stuff (rolling my own paintComponent() method).
    Any thoughts on how to figure out what is eating the CPU? I'm using NetBeans 6.7 and JDK 1.6_14 under Windows XP.
    Edited by: garrysimmons on Sep 15, 2009 1:52 PM
    Edited by: garrysimmons on Sep 15, 2009 2:57 PM
    Edited by: garrysimmons on Sep 15, 2009 3:02 PM

    It doesn't matter if it's a Swing timer or a Util timer. It behaves the same either way. That was one of the first things I tried.
    I ended up refactoring the code to go from a grid of individual controls (think checker board where each square is a control that draws itself), to a single "board" control that draws a grid. That seems to have fixed the issue. I can go in/out of Standby and the app doesn't eat a ton of CPU any more. The real problem may still be there, just too small of an effect to notice.
    I don't know why the original design would work fine before a Standby, but not after. Having ~200 little controls doing repaints twice a second must confuse something in the JVM/Windows versus having 4 large controls doing the same amount of drawing.
    It's working, so time to move on.

  • How to change the cursor type when a TableView class was added to a Swing application?

    We can resize column width by dragging the column divider in the table header. This is a built-in feature of the TableView class.
    Normally, the cursor will become to east-resize (or west-resize) type with positioning the cursor just to the right of a column header.
    However, I found that the cursor is remaining the default type at the same position if I integrate JavaFX into Swing Application. That is adding the TableView to a Scene, and then adding this Scene to a JFXPanel, finally, adding this JFXPanel to the JFrame.
    The sample codes are listing below:
    public class Run extends JFrame {
        Run() {
            setSize(600, 450);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            initComponents();
        private void initComponents() {
            final JFXPanel fxPanel = new JFXPanel();
            this.getContentPane().add(fxPanel);
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    initFX(fxPanel);
        private void initFX(JFXPanel fxPanel) {
            Scene scene = null;
            try {
                scene = FXMLLoader.load(
                    new File("res/fxml_example.fxml").toURI().toURL()
            } catch (Exception ex) {
                ex.printStackTrace();
            fxPanel.setScene(scene);
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    new Run().setVisible(true);
    fxml_example.fxml:
    <?xml version="1.0" encoding="UTF-8"?>
    <?import javafx.scene.Scene?>
    <?import javafx.scene.control.TableView?>
    <?import javafx.scene.control.TableColumn?>
    <Scene xmlns:fx="http://javafx.com/fxml">
        <TableView fx:id="tableView"
                   editable="true">
            <columns>
                <TableColumn text="COL1">
                </TableColumn>
                <TableColumn text="COL2">
                </TableColumn>
                <TableColumn text="COL3">
                </TableColumn>
                <TableColumn text="COL4">
                </TableColumn>
                <TableColumn text="COL5">
                </TableColumn>
            </columns>
        </TableView>
    </Scene>
    So, are there anyone can advise how to fix these codes; make the cursor can change to east-resize (or west-resize) type when this TableView class was added to a Swing application?

    Thanks for the report. I've just filed a JIRA issue: https://javafx-jira.kenai.com/browse/RT-34009
    //Anton.

  • What are the requirements to run a Swing application?

    I'm trying to send a simple swing application to a friend that has Mac OSX, but the buttons don't show up.
    Do people actually need the Java SDK in order for swing apps to work? Or is plain java enough? (He has normal java, because we play minecraft sometimes)
    Anyway, my buttons are not showing up on his computer, not even when I use the cross platform look at feel

    Here is the code I'm using, it's an application that makes the user select a folder and stuff will happen to it.
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    public class SomeGUI extends JFrame implements ActionListener, Runnable
        public JButton exit;
        public JButton run;
        JPanel panel;
        JFileChooser chooser;
        String returnpath;
        JLabel progress;
      public SomeGUI()
         try
         UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
         catch (ClassNotFoundException ex)
             Logger.getLogger(SomeGUI.class.getName()).log(Level.SEVERE, null, ex);
         catch (InstantiationException ex)
             Logger.getLogger(SomeGUI.class.getName()).log(Level.SEVERE, null, ex);
         catch (IllegalAccessException ex)
             Logger.getLogger(SomeGUI.class.getName()).log(Level.SEVERE, null, ex);
         catch (UnsupportedLookAndFeelException ex)
             Logger.getLogger(SomeGUI.class.getName()).log(Level.SEVERE, null, ex);
          setTitle("BenkyoAdd");
          setSize(206,100);
          setResizable(false);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setLocationRelativeTo(null);
          setVisible(true);
          panel = new JPanel();
          getContentPane().add(panel);
          panel.setLayout(null);
          run = new JButton("Run");
          run.setFocusable(false);
          run.setBounds(0,0,100,30);
          panel.add(run);
          run.addActionListener(this);
          progress = new JLabel("Please click run");
          progress.setFont(new Font("lol",Font.PLAIN,14));
          progress.setBounds(10, 30, 200, 50);
          panel.add(progress);
          exit = new JButton("Exit");
          exit.setFocusable(true);
          exit.setBounds(100, 0, 100, 30);
          panel.add(exit);
          exit.addActionListener(this);
          chooser = new JFileChooser();
          chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        public void actionPerformed(ActionEvent e)
         if(e.getSource().equals(exit))
             System.exit(0);
         if(e.getSource().equals(run))
             progress.setText("Select a folder...");
             chooser.showOpenDialog(panel);
             this.returnpath = chooser.getSelectedFile().getAbsolutePath();
             exit.setEnabled(false);
             run.setEnabled(false);
             progress.setText("Copying to output folder...");
             new Thread(this).start();
      public static void main(String args[])
          new SomeGUI();
        public void run()
         new Changer(this, this.returnpath);
         exit.setEnabled(true);
         exit.requestFocusInWindow();
         progress.setText("Done! You can now exit!");
    }

  • Help Needed in opening a HTML File from swing application

    Hi,
    I am opening a HTML file in Internet Explorer from my swing application.
    I am using the code given below
    private final static String WIN_FLAG = "url.dll,FileProtocolHandler";
    private final static String WIN_PATH = "rundll32";
    String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
    // url is HTML file Path
    Process p = Runtime.getRuntime().exec( cmd );
    The HTML file is opening up,but it always opens behind the swing application,that makes me every time to maximize the HTML file after it being opened up.
    I want to open it in front of the Swing Application.
    Any Help Please ?
    - Manikandan

    Check your Application's JFrame properties (may be ur Frame is set to be in top position ,always),and also check running your application in some other OS.

  • Opening a PDF file from a swing application in MAC

    HI everyone,
    Actually I am developing a swing application which should be executable in both windows and Mac (even other) platformes. In my panel I have an icon which leads to a pdf file. I saw in the following thread:
    http://forum.java.sun.com/thread.jspa?forumID=17&threadID=617767
    that we can use
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);to open what ever file in windows. I want to know what should I do if this application is running on Mac or Linux! I have never worked with these OS so I do not have any idea how to resolve the problem.
    Can anyone help me with this matter?? That would be really nice of you to reply :)
    Thanx and have a great day.

    Thank you for replaying so soon..
    Well you are right by using a widget and etc.. but the problem is that I have been told that this application should open a PDF file that has bookmarks to each chapter of the text and one can make a search on this text by using pdf search.. So I do not have any other choice than opening a pdf :D and my time is unfortunately limit.
    For solving the problem that the user may not have PDF reader.. well I have been told that user should install the pdf reader, so in my application package I am putting the installation file of PDF.
    But going back to my problem.. I guess is someway I have to get the OS type of the user and I have to do a SWITCH or something on the OS type and then change the content of the Runtime.exec(). But the question is how can I get the OS type and what should I change in Runtime.exec().
    So now any idea? any solution??

  • Invoking a Java swing application via its process id

    I have a Java swing application. What i am trying to do here is that when the user double-clicks the jar file to open it, if the Swing application is already open and is minimized, I need to maximize the open window and make it active.
    I tried using 'jps -l' command in my new instance, and with the help of Runtime.exec() am able to detect whether the application is already running or not, and if running, am able to get the process id and am displaying a message to user indicating the window is already open.
    But how do i maximize the window of an already running application? Is it possible?

    user13333704 wrote:
    I have a Java swing application. What i am trying to do here is that when the user double-clicks the jar file to open it, if the Swing application is already open and is minimized, I need to maximize the open window and make it active. That's not hard to do, but your proposed solution is hard to do. The usual way to have only one instance of a Java application running is this:
    Have the application open a SocketServer on a certain port number. Since only one process can listen on a port, the second instance of the application will fail when it tries to open the SocketServer. When that happens, the second instance should terminate instead of displaying its own GUI. Whether it terminates silently or whether it displays a dialog is up to you.
    If you want the second instance to communicate with the first instance, that's easy because the first instance is listening on the port. So the second instance could connect to that port and send a message to it. In your case the first instance would respond to that message by maximizing its GUI.

  • Swing application doesn't launch

    Hallo,
    I've programmed a simple swing-application that was til now functionning correctly. But today I can't launch this application. If I launch it with java -jar myprog.jar I get following information:
    Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: sun.font.FileFontStrike.createScalerContext(J[DZIIZFF)J
    at sun.font.FileFontStrike.createScalerContext(Native Method)
    at sun.font.FileFontStrike.<init>(Unknown Source)
    at sun.font.FileFont.createStrike(Unknown Source)
    at sun.font.Font2D.getStrike(Unknown Source)
    at sun.font.Font2D.getStrike(Unknown Source)
    at sun.font.CompositeStrike.getStrikeForSlot(Unknown Source)
    at sun.font.CompositeStrike.getFontMetrics(Unknown Source)
    at sun.font.FontDesignMetrics.initMatrixAndMetrics(Unknown Source)
    at sun.font.FontDesignMetrics.<init>(Unknown Source)
    at sun.font.FontDesignMetrics.getMetrics(Unknown Source)
    at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
    at javax.swing.JComponent.getFontMetrics(Unknown Source)
    at javax.swing.plaf.metal.MetalTitlePane$TitlePaneLayout.computeHeight(Unknown Source)
    at javax.swing.plaf.metal.MetalTitlePane$TitlePaneLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at javax.swing.plaf.metal.MetalRootPaneUI$MetalRootLayout.layoutContainer(Unknown Source)
    at java.awt.Container.layout(Unknown Source)
    at java.awt.Container.doLayout(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validate(Unknown Source)
    at java.awt.Window.pack(Unknown Source)
    at logviewer.Main$1.run(Main.java:61)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: sun.font.FileFontStrike.createScalerContext(J[DZIIZFF)J
    at sun.font.FileFontStrike.createScalerContext(Native Method)
    at sun.font.FileFontStrike.<init>(Unknown Source)
    at sun.font.FileFont.createStrike(Unknown Source)
    at sun.font.Font2D.getStrike(Unknown Source)
    at sun.font.Font2D.getStrike(Unknown Source)
    at sun.font.CompositeStrike.getStrikeForSlot(Unknown Source)
    at sun.font.CompositeStrike.getFontMetrics(Unknown Source)
    at sun.font.FontDesignMetrics.initMatrixAndMetrics(Unknown Source)
    at sun.font.FontDesignMetrics.<init>(Unknown Source)
    at sun.font.FontDesignMetrics.getMetrics(Unknown Source)
    at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
    at javax.swing.JComponent.getFontMetrics(Unknown Source)
    at javax.swing.plaf.metal.MetalTitlePane$TitlePaneLayout.computeHeight(Unknown Source)
    at javax.swing.plaf.metal.MetalTitlePane$TitlePaneLayout.preferredLayoutSize(Unknown Source)
    at java.awt.Container.preferredSize(Unknown Source)
    at java.awt.Container.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at javax.swing.plaf.metal.MetalRootPaneUI$MetalRootLayout.layoutContainer(Unknown Source)
    at java.awt.Container.layout(Unknown Source)
    at java.awt.Container.doLayout(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validate(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    after this output the application hangs, my windows commad prompt doesn't show the prompt.
    Secondary, it is not possible to launch the Java-Applet in Control Panel of Windows. It happans nothing.
    Whats going wrong? My program didn't change, it's the same program I was using since longer time. What could I do to make it function correctly?
    with regards
    Rafal Ziolkowski

    Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: sun.font.FileFontStrike.createScalerContext(J[DZIIZFF)J
    UnsatisfiedLinkError indicates that the JVM cannot find a native method's definition. Generally this means that the shared object file (.so on unices, .dll on Windows) cannot be found by the JVM.
    Since the missing method is visibly Sun's code, presumably a built-in JRE method, that probably means your JRE/JDK install has been corrupted (corroborated by a quick Google search on the obvious keywords).
    Try reinstalling the JRE or JDK.
    Secondary, it is not possible to launch the Java-Applet in Control Panel of Windows. It happans nothing. I don't understand this sentence. What are you doing exactly, and how is that related to the first question?
    Much luck,
    J.

  • Exiting a swing application

    Hello,
    I have a swing application that behaves differently depending on if I go to file->exit or if I hit the X on the frame border.
    Specifically, some threads keep running when I go to file->exit.
    I would like for the app to behave as if they hit the X when they go to file->exit and have all threads stop.
    The code I have for file->exit is ....
            exitItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    frame.dispose();
            });Is there something else I could be doing here to make it kill everything?
    Thanks,
    ~Eric

    Hello,
    I have a swing application that behaves differently
    depending on if I go to file->exit or if I hit the X
    on the frame border.
    Specifically, some threads keep running when I go to
    file->exit.
    I would like for the app to behave as if they hit the
    X when they go to file->exit and have all threads
    stop.
    The code I have for file->exit is ....
            exitItem.addActionListener(new
    ActionListener() {
    public void actionPerformed(ActionEvent
    event) {
    frame.dispose();
    });there something else I could be doing here to make it
    kill everything?
    System.exit(0);

  • BackGround picture for a Swing application??

    hi,
    once I got a nice idea while watching some webpages. we can give a background picture for a webpage in <body> tag?
    I want to do same thing for any Swing application. Currently I am working on that issue. Any suggestions are welcome!!
    santhosh

    Hi everybody!
    Finally I got it. now Using this We can enable background for any swing application.
    the complete code is shown here. If you have any problems regarding this code, please mail to [email protected]
    /******************************[TexturedImageIcon.java]***********************/
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import javax.swing.*;
    /* this is used to generate a tiled image from a given image file.*/
    public class TexturedImageIcon extends ImageIcon
         private Dimension size = new Dimension(10, 10);
         BufferedImage bimg1,bimg;
         Graphics2D g2;
         ComponentListener cl = new ComponentAdapter(){
              public void componentResized(ComponentEvent ce){
                   Component c = (Component)ce.getSource();
                   size = c.getSize();
                   createImage();
         public void setImage(String filename){
              super.setImage(new ImageIcon(filename).getImage());
              bimg1=null;
              createImage();
         public TexturedImageIcon(Component comp, Image img){
              super(img);
              addListener(comp);
         public TexturedImageIcon(Component comp, String filename){
              super(filename);
              addListener(comp);
         public TexturedImageIcon(Component comp, URL url){
              super(url);
              addListener(comp);
         private void addListener(Component comp){
              comp.addComponentListener(cl);
         private void createImage(){
              bimg = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
              g2 = bimg.createGraphics();
              Rectangle2D rect = new Rectangle2D.Float(0,0,size.width-1, size.height-1);
              Rectangle2D tr = new Rectangle2D.Double(0,0,super.getIconWidth(), super.getIconHeight());
              if(bimg1==null){
                   bimg1 = new BufferedImage(super.getIconWidth(), super.getIconHeight(), BufferedImage.TYPE_INT_RGB);
                   Graphics2D g = bimg1.createGraphics();
                   g.drawImage(super.getImage(), null, null);
              TexturePaint tp = new TexturePaint(bimg1, tr);
              g2.setPaint(tp);
              g2.fill(rect);
         public int getIconWidth(){ return size.width; }
         public int getIconHeight(){ return size.height; }
         public Image getImage(){
              System.out.println("asked");
              return bimg;
         public void paintIcon(Component c, Graphics g, int x, int y){
              Graphics2D g2d =(Graphics2D)g;
              g2d.drawImage(bimg, null, null);
         public static void main(String[] args){
              JFrame f = new JFrame();
              f.setSize(300,300);
              JLabel label = new JLabel();
              label.setBackground(Color.white);
              label.setBorder(BorderFactory.createRaisedBevelBorder());
              label.setIcon(new TexturedImageIcon(label, "world2.gif"));
              f.getContentPane().setLayout(new BorderLayout());
              f.getContentPane().add(label, BorderLayout.CENTER);
              f.show();
    /*********************************[JFCUtils.java]************************/
    /*The main logic to enable background picture lies in this class*/
    public class JFCUtils{
         public static ContainerListener cl = new ContainerAdapter(){
              public void componentAdded(ContainerEvent ce){
                   JComponent child = (JComponent)ce.getChild();
                   child.setOpaque(false);
                   child.addContainerListener(this);
                   addlisteners(child);
         public static TexturedImageIcon enableBackGround(JFrame f, String filename){
              ((JPanel)f.getContentPane()).setOpaque(false);
              JLayeredPane lp = f.getLayeredPane();
              JLabel label = new JLabel();
              TexturedImageIcon icon = new TexturedImageIcon(label, filename);
              label.setIcon(icon);
              JPanel panel = new JPanel(new BorderLayout());
              panel.add(label, BorderLayout.CENTER);
              lp.add(panel, new Integer(Integer.MIN_VALUE));
              Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
              panel.setBounds(0, 0, screen.width,screen.height);
              addlisteners((JComponent)f.getContentPane());
              return icon;
         private static void addlisteners(Component c){
              c.toString();
              if(c instanceof JComponent) ((JComponent)c).setOpaque(false);
              if(c instanceof Container){
                   Container ct = (Container)c;
                   ct.addContainerListener(cl);          
              for(int i=0; i<ct.getComponentCount(); i++){ //recursivly make all subcomponents transparent
                   Component child = (Component)ct.getComponent(i);
                   addlisteners(child);
         public static void main(String[] args){
              JFrame f = new JFrame();
              enableBackGround(f, "bg.jpg");
              JButton b = new JButton("fdfdfdfd");
              f.getContentPane().add(b, BorderLayout.NORTH);
              f.setSize(300,300);
              f.show();
    /*************************************[UserDialog.java]**************************/
    //to check how a swing application with background looks like
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class UserDialog extends JDialog
         JPanel contents = (JPanel)getContentPane();
         JTextField shortField = new JTextField(20);
         JTextField nameField = new JTextField(20);
         JTextField emailField = new JTextField(20);
         JTextField smtpServerField = new JTextField(20);
         JTextField pwdField = new JPasswordField(20);
         JTextField pwdField1 = new JPasswordField(20);
         boolean okay = false;
         public UserDialog(JFrame owner){
              super(owner, "New User Details", true);
              initComponents();
              pack();
              setResizable(false);
         public UserDialog(JDialog owner){
              super(owner, "New User Details", true);
              initComponents();
              pack();
              setResizable(false);
         private void initComponents(){
              JPanel west = new JPanel(new GridLayout(0, 1));
              west.add(new JLabel("Short Name"));
              west.add(new JLabel("Full Name"));
              west.add(new JLabel("Email"));
              west.add(new JLabel("SMTP Server"));
              west.add(new JLabel("Password"));
              west.add(new JLabel("Confirm Password"));
              JPanel east = new JPanel(new GridLayout(0, 1));
              east.add(shortField);
              east.add(nameField);
              east.add(emailField);
              east.add(smtpServerField);
              east.add(pwdField);
              east.add(pwdField1);
              JPanel south = new JPanel();
              JButton ok = new JButton("Ok");
              JButton cancel = new JButton("Cancel");
              south.add(ok);
              south.add(cancel);
              contents.setBorder(JFCUtils.border);
              contents.setLayout(new BorderLayout(10, 10));
              contents.add(west, BorderLayout.WEST);
              contents.add(east, BorderLayout.EAST);
              contents.add(south, BorderLayout.SOUTH);
              ActionListener al = new ActionListener(){
                   public void actionPerformed(ActionEvent ae){
                        okay = ae.getActionCommand().equals("Ok");
                        setVisible(false);
              ok.addActionListener(al);
              cancel.addActionListener(al);
         private void clearFields(){
              shortField.setText("");
              nameField.setText("");
              emailField.setText("");
              smtpServerField.setText("");
              pwdField.setText("");
              pwdField1.setText("");
         public User getUser(){
              clearFields();
              okay = false;
              show();
              if(okay) return new User(shortField.getText(), nameField.getText(), emailField.getText(), smtpServerField.getText(), pwdField.getText());
              else return null;
         public static void main(String[] args){
              Dialog dlg = new UserDialog();
              TexturedImageIcon ticon = JFCUtils.enableBackGround(f, "bg.jpg");.show();
              //we can change the background picture by calling ticon.setImage(...) at runtime.

Maybe you are looking for

  • Tipos de nota fiscal

    Oi, Alguém pode me explicar qual é a diferença entre os grupos G1, G4, R1 e R4 tipos de nota fiscal?? Além disso não iam certeza se esses são os tipos de nota fiscal padrão definido pela SAP? adv

  • What are the views/fields that we can't change by Mass maintenance of MMR(material master record)?

    Hello friends,           I would like to know the fields/views that we can not change by using mass maintenance of MMR if there are open PO for that particular material in concern. Likewise there was a question in SAP certification exam having option

  • Links doesn't work

    Hi, I finshed my form and noticed that links in the form doesn't work. I tested in both reader and acrobat. Does anybody know what is going on? Thanks

  • JComboBox listener problem

    Hi all, I have following problem, i use combobox and i need to write listener for selecting item. But both ActionListener and ItemListener are unusable for me, because i dont know how to differ between selecting item when combobox is poped up. I dont

  • Scrollable text frames

    when i go to preview my iPad app that I am designing with Adobe inDesign CC using digital publishing, it gets rid of my scrollable text frames??