Update a JFrame.

Hi, I am new to java GUI. I created a JFrame containing 3 JPanels and a JLable, the JLabel contains a icon which is a graphic I generated. But as the program runs, the user can update some variables and the graph should change and some other labels in the Jpanels should change too, but I am not sure how can I update the JFrame after I change the value in the variables.
another quich Q is that I have a textfield, and whenever the user enters something in there and press the "entery" key, I should do some action, which listener should I use for the "enter" key? thanx

import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.util.Random;
import javax.swing.*;
public class UpdateDemo {
  static String msg = "";
  static Random seed = new Random();
  static int
    topCount = 1,
    midCount = 1,
    lowCount = 1;
  public static void main(String[] args) {
    final JLabel label = new JLabel() {
      Font font = new Font("lucida sans regular", Font.PLAIN, 18);
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setFont(font);
        g2.setPaint(Color.blue);
        float width = getWidth();
        float height = getHeight();
        FontRenderContext frc = g2.getFontRenderContext();
        LineMetrics metrics = font.getLineMetrics(msg, frc);
        float msgWidth = (float)font.getStringBounds(msg, frc).getWidth();
        float descent = metrics.getDescent();
        g2.drawString(msg, (width - msgWidth)/2,
                           (height + metrics.getHeight())/2 - descent);
    label.setPreferredSize(new Dimension(300,30));
    label.setOpaque(true);
    label.setBackground(Color.white);
    final GridBagLayout gridbag = new GridBagLayout();
    final JPanel centerPanel = new JPanel(gridbag);
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = gbc.REMAINDER;
    Dimension panelSize = new Dimension(300,100);
    final JPanel
      topPanel = new JPanel(),
      midPanel = new JPanel(),
      lowPanel = new JPanel();
    final JPanel[] panels = {
      topPanel, midPanel, lowPanel
    final JLabel
      topLabel = new JLabel("topPanel color 1"),
      midLabel = new JLabel("midPanel color 1"),
      lowLabel = new JLabel("lowPanel color 1");
    JLabel[] labels = {
      topLabel, midLabel, lowLabel
    for(int i = 0; i < 3; i++) {
      panels.setPreferredSize(panelSize);
panels[i].setBackground(getPanelColor());
panels[i].add(labels[i]);
centerPanel.add(panels[i], gbc);
final JTextField tf = new JTextField(18);
tf.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
msg = tf.getText();
label.repaint();
final JButton
topButton = new JButton("top"),
midButton = new JButton("mid"),
lowButton = new JButton("low");
ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton button = (JButton)e.getSource();
if(button == topButton) {
topPanel.setBackground(getPanelColor());
topLabel.setText("topPanel color " + ++topCount);
if(button == midButton) {
midPanel.setBackground(getPanelColor());
midLabel.setText("midPanel color " + ++midCount);
if(button == lowButton) {
lowPanel.setBackground(getPanelColor());
lowLabel.setText("lowPanel color " + ++lowCount);
centerPanel.repaint();
topButton.addActionListener(l);
midButton.addActionListener(l);
lowButton.addActionListener(l);
JPanel southPanel = new JPanel(gridbag);
gbc.weightx = 1.0;
gbc.insets = new Insets(5,0,5,0);
southPanel.add(tf, gbc);
gbc.gridwidth = 1;
southPanel.add(topButton, gbc);
gbc.gridwidth = gbc.RELATIVE;
southPanel.add(midButton, gbc);
gbc.gridwidth = gbc.REMAINDER;
southPanel.add(lowButton, gbc);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(label, "North");
f.getContentPane().add(centerPanel, "Center");
f.getContentPane().add(southPanel, "South");
f.pack();
f.setLocation(400,200);
f.setVisible(true);
private static Color getPanelColor() {
int r = seed.nextInt(256);
int g = seed.nextInt(256);
int b = seed.nextInt(256);
return new Color(r,g,b);

Similar Messages

  • Updating a JFrame

    Hi all,
    I've got a problem (ya, another :P). I made a JFrame with a JPanel into it. But when i pressed a button, the ContentPane clears and the JPanel get a new content.
    But the problem is:
    When i pressed the button, it works. Well, i have to resize the frame first. So that means that the JFrame (with the JPanel) doesn't refresh!
    I tryed something with validate() and revalidate but that doesn't work :S!
    I hope someone can help me with this problem!
    I put the code down here!
    Ty all,
    Jasper
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Times_of_War_Frame extends JFrame
         Times_of_War_Ingame ingame_glass = new Times_of_War_Ingame();
         Times_of_War_Menu menu_glass = new Times_of_War_Menu();
         Container content = getContentPane();
         JScrollPane scrollPane;
         int place_id = 0;
         Insets frame_info;
         public Times_of_War_Frame()
              setTitle("Times of War :: The age of Destruction");
              setSize(800, 600);
              setLocation(0,0);
              frame_info = getInsets();
              setIconImage(new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\logo's\\icon.gif").getImage());
              this.addWindowListener
                   new WindowAdapter()
                        public void windowClosing(WindowEvent e)
                             Times_of_War_Frame.this.windowClosed();
              Times_of_War_Situation(place_id);
        public void Times_of_War_Situation(int place_id_set)
             content.removeAll();
             if (place_id_set == 0)
                  Times_of_War_Menu_internal();
                  System.out.println("Menu loaded");
             if (place_id_set == 1)
                  Times_of_War_Ingame_internal();
                  System.out.println("Game loaded");
             repaint();
        public void Times_of_War_Ingame_internal()
             ingame_glass.setVisible(true);
              setGlassPane(ingame_glass);
             JPanel topPanel = new JPanel();
                   topPanel.setLayout(new BorderLayout());
                   //Background for status bar//
                        JPanel Status_Panel = new JPanel();
                        Status_Panel.setLayout(new FlowLayout(0, 0, 0));
                        Icon status_1 = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\status_bar\\status_background.jpg");
                        JLabel status_label_1 = new JLabel(status_1);
                        Status_Panel.add(status_label_1);
                        topPanel.add(Status_Panel, BorderLayout.PAGE_START);
                   //Bars ready//
                   //Content//
                        JPanel Content_Panel = new JPanel();
                        Content_Panel.setLayout(new FlowLayout(0, 0, 0));
                        Icon background = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\backgrounds\\dirt.jpg");
                        JLabel background_label = new JLabel(background);
                        Content_Panel.add(background_label);
                        topPanel.add(Content_Panel, BorderLayout.LINE_START);
                        content.add(topPanel);
                   //Content ready//
        public void Times_of_War_Menu_internal()
             menu_glass.setVisible(true);
              setGlassPane(menu_glass);
              JPanel topPanel = new JPanel();
                   topPanel.setLayout(null);
                   topPanel.setBackground(Color.black);
                   //Content//               
                        Icon button_1_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_1_normal.jpg");
                        Icon button_2_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_1_over.jpg");
                        Icon button_3_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_2_normal.jpg");
                        Icon button_4_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_2_over.jpg");
                        Icon button_5_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_3_normal.jpg");
                        Icon button_6_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_3_over.jpg");
                        Icon button_7_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_4_normal.jpg");
                        Icon button_8_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_4_over.jpg");
                        Icon button_9_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_5_normal.jpg");
                        Icon button_10_icon = new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\menu\\button_5_over.jpg");
                        JButton button_1 = new JButton(button_1_icon);
                        button_1.setBorderPainted(false);
                        button_1.setRolloverEnabled(true);
                        button_1.setRolloverIcon(button_2_icon);
                        button_1.addActionListener(
                        new     ActionListener()
                             public void actionPerformed(ActionEvent e)
                                  place_id = 1;
                                  Times_of_War_Situation(place_id);
                        JButton button_2 = new JButton(button_3_icon);
                        button_2.setBorderPainted(false);
                        button_2.setRolloverEnabled(true);
                        button_2.setRolloverIcon(button_4_icon);
                        JButton button_3 = new JButton(button_5_icon);
                        button_3.setBorderPainted(false);
                        button_3.setRolloverEnabled(true);
                        button_3.setRolloverIcon(button_6_icon);
                        JButton button_4 = new JButton(button_7_icon);
                        button_4.setBorderPainted(false);
                        button_4.setRolloverEnabled(true);
                        button_4.setRolloverIcon(button_8_icon);
                        JButton button_5 = new JButton(button_9_icon);
                        button_5.setBorderPainted(false);
                        button_5.setRolloverEnabled(true);
                        button_5.setRolloverIcon(button_10_icon);
                        topPanel.add(button_1);
                        topPanel.add(button_2);
                        topPanel.add(button_3);
                        topPanel.add(button_4);
                        topPanel.add(button_5);
                        button_1.setBounds(305, 200, 190, 26);
                        button_2.setBounds(305, 260, 190, 26);
                        button_3.setBounds(305, 320, 190, 26);
                        button_4.setBounds(305, 380, 190, 26);
                        button_5.setBounds(305, 440, 190, 26);
                        content.add(topPanel);
                   //Content ready//
         public void paint(Graphics g)
              super.paint(g);
        protected void windowClosed()
              System.exit(0);
    }and
    import java.awt.*;
    public class Times_of_War
        public static void main(String[] args)
            Times_of_War_Frame frame = new Times_of_War_Frame();
            frame.setVisible(true);
    }

    Ty very much!
    But still 1 thing :), could you tell me where i have to put them?
    Regards,
    Jasper

  • Updating a JFrame with a new panel

    Hi,
    i want to switch a JPanel placed in my JFrame. But if i do so, i always have to maximize the window and then bring it back again, to see the changes work completely.
    I tried both repaint() and validate() but both do not work that I always have to maximize the window to see the changes.
    Can anybody help me to solve this?
    Thanks for answers in advance!

    I don't know exactly what you mean by switching a JPanel.
    You might want to read the CardLayout tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html
    If you replace a JPanel you need to call revalidate on the parent of the JPanel you are replacing.
    If you want further help post a Short, Self Contained, Compilable and Executable, Example Program ([url http://homepage1.nifty.com/algafield/sscce.html]SSCCE) that demonstrates the problem.
    And don't forget to use [url http://forum.java.sun.com/help.jspa?sec=formatting]code formatting when posting code.

  • Updating a JFrame's Background every second

    Hello all,
    What i want to achieve here is very simple, I have a class which extends JFrame. In my constructor, i create my GUI (background and buttons etc.), so here is my code :
    //other imports goes here
    public class TestBg extends JFrame implements ActionListener{
         //constructor
         public TestBg(){
              //.. other codes go in here
              //set the first background
              setContentPane(getImage());
              //create a timer which is invoked every second
              Timer timer = new Timer(1000,this);
              timer.start();
         //close constructor
         public void actionPerformed(ActionEvent e){
              //print a statement to see if method is invoked
              System.out.println("Method invoked");
              setContentPane(getImage());
    }//close classlets say the method getImage() returns a JLabel, which set it to the JFrame's background.
    The actionPerformed method is invoked every second, but the background isn't changing ( getImage() returns a different JLabel each time)
    what extra code do i have to add ? thanks.
    NOTE : I just discovered something, i think the JFrame needs to be repainted. Because whenever i resize the Frame, the background changes!, but i do not know how to 'referesh' the JFrame without resizing it.
    Message was edited by:
    TrAnScEnD3nT
    Message was edited by:
    TrAnScEnD3nT

    That's because You add them to container that is an original content pane. Then when You call setContentPane this container is thrown away with all it's content and new "empty" container is put in that place.
    I advise using a JPanel as a contentPane and don't change it on the run. Insted you can use the timer to repaint that panel with some image specified.

  • JFrame update problem

    Hi.
    Having some trouble figuring out how to hack this one:
    I have a JFrame that has a child panel which inturn contains two childpanels.
    In the one childpanel i have a JButton which, when pressed, invokes a method that adds content to the sibling JPanel.
    I'm trying to figure out how to update the JFrame so that the new panels contents are displayed. Currently i have to resize the window manually with the mouse to get the content updated. I have tried repainting all the panels but no luck.
    Any suggestions are welcome :)

    hmm...
    This is what i got so far.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.URL;
    public class Arkiv implements ActionListener {
         //declare static top level JFrame
         static JFrame arkivRamme;
         //declare panels
        JPanel mainPanel, hovedValgPanel, innputPanel;
        JButton leggTilBtn, visBtn;
         JComboBox type;
         int hovedStatus = 0;
         //constructor
        public Arkiv() {
            //create sibling sub panels to hold widgets
            hovedValgPanel = new JPanel(new GridLayout(0, 1));
            innputPanel = new JPanel();
              innputPanel.setLayout(new BoxLayout(innputPanel, BoxLayout.PAGE_AXIS));
            //Create the main panel to contain the two sub panels.
            mainPanel = new JPanel();
            mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
              //Add various widgets to the sub panels.
            initial();
            //Add the sibling sub panels to the main panel.
            mainPanel.add(hovedValgPanel);
            mainPanel.add(innputPanel);
              mainPanel.revalidate();
         //Set up the widgets in the hovedValgPanel
        public void initial() {
              leggTilBtn = new JButton("Legg til");
              leggTilBtn.addActionListener(this);
              visBtn = new JButton("Vis");
              visBtn.addActionListener(this);
              hovedValgPanel.add(leggTilBtn);
              hovedValgPanel.add(visBtn);
              hovedValgPanel.revalidate();
         //Add widgets for 'adding an item' to the innputPanel
         public void leggTil() {
              String[] typeValg = { "Velg Type", "Audio", "Video"};
              type = new JComboBox(typeValg);
              type.addActionListener(this);
              innputPanel.add(type);
              innputPanel.revalidate();
        public void actionPerformed(ActionEvent event) {
            if ("comboBoxChanged".equals(event.getActionCommand())) {
                System.out.println("Kombobox endret:... \n");
              else if(event.getActionCommand().equals("Legg til")){
                   innputPanel.removeAll();
                   System.out.println("Legg til:... \n");
                   leggTil();
                   arkivRamme.pack();
              else if(event.getActionCommand().equals("Vis")){
                   System.out.println("Vis:... \n");
              else{
                   System.out.println("Feil med event.getActionCommand:...\n");
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create a new instance of Arkiv.
            Arkiv arkivet = new Arkiv();
            //Create and set up the window.
            arkivRamme = new JFrame("Arkiv");
            arkivRamme.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            arkivRamme.getContentPane().add(arkivet.mainPanel);
            //Display the window.
            arkivRamme.pack();
            arkivRamme.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }Message was edited by:
    kenrg
    Message was edited by:
    kenrg

  • Updating JFrame with creating a new one

    Hi All,
    I instantiate an object as follows, which creates a JFrame
    _imageOutput = new ImageOutput(array, offsetArray);
    however this is inside a loop and instead of updating the JFrame is creates a new one each time. How can I stop it from creating a new one each time?
    Thanks,
    Enda.

    How can I stop it from creating a new one each time?If you do
    _imageOutput = new ImageOutput(array, offsetArray);
    then OF COURSE it creates a NEW ImageOutput object.
    If you want to update it (whatever that mean) then add a new method in that object like Update(). Then everytime you want to update it, use
    _imageOutput.Update() .  You can refresh the graphics of a JComponent with repaint().                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Updating JFrame

    lets say that a JFrame with a JPanel inside was initialized and looked like
    2 3 4
    -1 5 6
    if i were to swap 4 with 6
    how would i go about updating the JFrame

    --did you just use JLabel to print those values?  you can use the getter and setter methods of you used JLabel, JButton... you can try to repaint it using the paint method...
    --there's a bunch of ways on how to make the values swap...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to update the second JComboBox according selection in first JComboBox??

    I am having a hard time to update the second JcomboBox according to the selection of the first JcomboBox. For example, the content of the first JcomboBox is {city, rent}. When "city" is selected, the content of the second JcomboBox should be set to a number of cities. When "rent" is selected, the content of the second JcomboBox should be set to a range of rent.
    Since I have to detect the selection in actionperformed(), where the JcomboBoxes have been added to a Panel, and my JFrame setContentPane() to this Panel, I don't know how to update the JFrame or the Panel. I can make the old JFrame disappear and a new JFrame appear instead, but this is not what I want. I tried method update(Graphics) and removeAll(), and never made it work.
    I would greatly appreciate if anyone could give me any help.

    Thanks for your response. I fixed the problem in the following clumsy way:
    frame.getContentPane().remove(mainPanel);
    mainPanel.remove(box2);
    if(box1.compareTo("city")==0)
    box2 = new JComboBox(cities);
    else if(box1.compareTo("rent")==0)
         box2 = new JComboBox(rents);     
    else if(box1.compareTo("type")==0)
         box2 = new JComboBox(types);
    box2.setBounds(305, 30, 90, 20);
    mainPanel.add(box2);
    frame.getContentPane().add(mainPanel);
    Maybe there is a better way, but I don't know, and I don't understand your suggestion, could you further explain it? Thanks a lot.
    lz22

  • Update  JComponents

    i dont know how to update Jcomponents and Jframes etc..
    i have a JFrame, there are some JPanels in it...
    while inilitalizing few Jbuttons,Jscrollpane etc are added in JPanels by layout manger
    when some action event occurs, i can write
    actionPerformed(actionEvent ae) {
    remove(scroller)
    add(new Jbutton("Go"));
    etc...
    how do i be able to see the changes made by adding and removing components??
    but how do i update one particular component like say scroller??
    (its a JScrollpane)
    and how do i update whole JFrame??
    Just like repaint() updates top most painted things...i want to be able to update JComponent like scroller etc.
    when i minimize and restore the frame....the new addition and removal of components is updated..
    so which method gets called when we minimize and restore??
    pls answer each question.....
    Message was edited by:
    subhasnagre

    pls answer each question.....same answer for all
    "look up the api docs" / "search the forum" for
    validate();
    revalidate();

  • Best way to repaint/refresh JFrame classes.

    Hello everyone,
    I am developing a small application for my studies. I have several classes many representing a user form allowing interaction with my system.
    One of my first class instances is a Menu Screen from which the user can for example update their details. When the Update Details frame is closed by the user I invoke
    frameName.setVisible(false);
    frameName.dispose();This removes the Update Details frame and the Menu Screen is now fully visible.
    However this screen does not get refreshed and remains partially obscured by the background color of the JFrame, even if I bring say a browser to the foreground and then click the original Menu Screen to the foreground it does not refresh the Menu Screen and remains half painted.
    I was wondering about a few things.
    1. Is there a way of detecting when the current JFrame has just received the focus, at which point I could repaint the screen.
    2. Is there a way of Menu Screen discussed above being able to detect the closure of the Update Details JFrame (a separate class) and then take appropriate steps to repaint/refresh itself.
    3. Ideally what I would like to do is Hide the Menu Screen then allow the user to interact with their menu selection and then Un-hide the Meun Screen when the user is done interacting with their menu selection.
    4. Are there any tutorials on this type of thing, that anynone could direct me to.
    Thank you for your consideration.
    Cheers
    Mark

    Hello everyone,
    I am developing a small application for my studies. I
    have several classes many representing a user form
    allowing interaction with my system.
    One of my first class instances is a Menu Screen from
    which the user can for example update their details.
    When the Update Details frame is closed by the user I
    invoke
    frameName.setVisible(false);
    frameName.dispose();This removes the Update Details frame and the Menu
    Screen is now fully visible.
    However this screen does not get refreshed and remains
    partially obscured by the background color of the
    JFrame, even if I bring say a browser to the
    foreground and then click the original Menu Screen to
    the foreground it does not refresh the Menu Screen and
    remains half painted.
    I was wondering about a few things.
    1. Is there a way of detecting when the current JFrame
    has just received the focus, at which point I could
    repaint the screen.
    2. Is there a way of Menu Screen discussed above being
    able to detect the closure of the Update Details
    JFrame (a separate class) and then take appropriate
    steps to repaint/refresh itself.
    3. Ideally what I would like to do is Hide the Menu
    Screen then allow the user to interact with their menu
    selection and then Un-hide the Meun Screen when the
    user is done interacting with their menu selection.
    4. Are there any tutorials on this type of thing, that
    anynone could direct me to.
    Thank you for your consideration.
    Cheers
    Mark

  • JFrame.pack() causes problems with jtabbedpane(making new tabs)and resizing

    I have a JFrame with a JTabbedPane inside of it. Inside of each tab I put a JPanel with a JTextArea in it. When I create a new tab, I do something like textArea.requestFocusInWindow();
    However, this will not work unless I do a frame.pack() right after I created the new tab and right before that line of code.
    This in turn causes another problem. If I resize the jframe and then create a new tab, the window will snap back to the size it had before creating the tab. I assume this has to do with the pack() function, however nothing else I try will make the cursor blink in the JTextArea.
    Is there a solution to this...either something to make the cursor blink or something other than the pack function to update the JFrame?
    Thank you

    This posting should help you out:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=581478

  • More on Updating Swing Components during long operations...

    After reading thru a few posts here, I've come to the conclusion that what I need is going to be much more difficult than I'd planned. Neverthess i'll try to explain...
    I have a JFrame which contains a simple JLabel and JProgressBar. While I am performing a long network operation, I am making calls to a Thread class (which contains the above components) to update the JFrame indicating the current status. Normally I have no problem with this as the paintImmediately method suffices. However, when I call this long operation from the constructor of a larger, more complex JFrame, the GUI remains unresponsive (despite the plethora of paintImmediately calls that are executed) until the user clicks in the threaded progress box.
    Unfortunately the SwingWorker solution will not work for me as I need to be completely backwards compatible with JDK 1.3 (supporting Mac OSX 10.X). Oddly enough tho, I don;t get these problems when I use the same code in JDK 1.1.8 on Mac OS9.
    Any ideas?
    thanks!

    heh...looks like it was a simple thing afterall :)
    The JDialog (not JFrame) just needed focus.
    heh...is it friday yet? ;)

  • Dynamically updating the window title?

    Is there a way to dynamically update the JFrame window title of my program?

    The "substring" method allows you to get any subpart
    of a String (and thus, in effect, "subtract" characters
    from a String).
    Please take a closer look at
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
    Please don't ask every little question.

  • Mimicking Transparency on a JFrame

    Hi I've created the following code to update a JFrame with the background image of the desktop
    import java.awt.MouseInfo;
    import java.awt.Point;
    import java.awt.PointerInfo;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.Timer;
    public class MovementListener implements MouseListener, ActionListener{
         private JFrame f;
         private Point start,end,start1,end1;
         private Timer t,t2;
         private float fps = 30.0f;
         private BackgroundImage jp;
         private BufferedImage screenImg;
         public  MovementListener(JFrame frame, BackgroundImage jp){
              this.f = frame;
              this.jp = jp;
              t = new Timer(Math.round(1000.0f/(fps)), this);
              t.stop();
              t2 = new Timer(Math.round(1000.0f/(fps)), this);
              t2.start();
         public void mouseClicked(MouseEvent arg0) {}
         public void mousePressed(MouseEvent arg0) {
              if(arg0.getButton() == MouseEvent.BUTTON1 && inVisibleBounds(arg0.getPoint())){
                   if(t.isRunning())
                        t.restart();
                   else t.start();
                   start = arg0.getPoint();
                   end = start;
         private boolean inVisibleBounds(Point p){
              return jp.contains(p);
         public void mouseReleased(MouseEvent arg0) {
              if(arg0.getButton() == MouseEvent.BUTTON1 && start != null){
                   end = arg0.getPoint();
                   if(!checkEquality(start, end)){
                        moveFrame(start,end);
                   t.stop();
                   start1 = null;
                   end1 = null;
                   start = null;
                   end = null;
         public void mouseEntered(MouseEvent arg0){}
         public void mouseExited(MouseEvent arg0) {}
         private boolean checkEquality(Point a, Point b){
              return a.x == b.x && a.y == b.y;
         private void moveFrame(Point start, Point end){
              Point p = f.getLocation();
              //move horizontally
              p.x += end.x - start.x;
              //move vertically
              p.y += end.y - start.y;
              //f.setVisible(false);
              resetUnderImg(p); //get new Image
              jp.setImage(new ImageIcon(screenImg)); //change background
              //f.setVisible(true);
              f.setLocation(p); //move frame
         public void actionPerformed(ActionEvent arg0) {
              PointerInfo pi = MouseInfo.getPointerInfo();
              resetUnderImg(pi.getLocation());
              //t2 just updates image
              if(arg0.getSource().equals(t2))return;
              if(start1 == null){
                   start1 = pi.getLocation();
                   return;
              }else if(end1 == null){
                   end1 = pi.getLocation();
              if(!checkEquality(start1, end1)){ //check if moved
                   moveFrame(start1,end1);
                   start1 = end1;
                   end1 = null;
         public void resetUnderImg(Point p) {
               int x = p.x;
               int y = p.y;
               int w = f.getWidth();
               int h = f.getHeight();
               screenImg = BackgroundImage.getBackgroundImage();
               if(x + w > screenImg.getWidth())
                    w = screenImg.getWidth() - x;
               if(y + h > screenImg.getHeight())
                    h = screenImg.getHeight() - y;
               screenImg = screenImg.getSubimage(x,y,w,h);
    }As the JFrame is Undecorated this code actually manages Dragging and updating the background my problem is not tin the dragging part of the code it's actually in the repainting part i.e. in the code
    private void moveFrame(Point start, Point end){
              Point p = f.getLocation();
              //move horizontally
              p.x += end.x - start.x;
              //move vertically
              p.y += end.y - start.y;
              //f.setVisible(false);
              resetUnderImg(p); //get new Image
              jp.setImage(new ImageIcon(screenImg)); //change background
              //f.setVisible(true);
              f.setLocation(p); //move frame
         }if I uncomment setVisible(..) I get a flicker�if I don't I get an image that looks like the frames per second on a movie is too slow.... if you know what I mean
    Any help would be appreciated

    Melissa,
    You are not clearly descrbing the situation.
    How many different ink colors
    will be printed?
    Will you use the same
    number of inks regardless of shirt color?
    If you are printing one ink, regardless of the color of the shirt, then you can:
    1. Make the block in your design one SPOT color.
    2. Position the process white lines on top of the block. (No transparency, no overprint.)
    3. Print the spot color SEPARATION.
    The result is a print of a black block with lines "knocked out of it."
    The resulting screen positive can now be used on any color shirt. The printer can simpy use a different colored ink to print it on a black shirt.
    You can also:
    1. Make the block in your design process black.
    2. Position the process white lines on top of the block. (No transparency, no overprint.)
    3. Print a composite.
    The result is the same: A print of a black block with lines "knocked out of it."
    I think what you're misunderstanding is: When working with spot colors,
    it really doesn't matter what color value is applied to the spot color Swatch, but you must print as separations. Regardless of what color the spot color is, the separation print is simply a black image. It can be used to make a printing plate for any color someone choses to load the press (or silkscreen) with.
    JET

  • IllegalArgumentException in a JTabbedPane

    Hi,
    I am creating a pane that has several tabs. I receive an IllegalArgumentException which is telling me I cannot add a window to a container. Here is part of my code (not all of it, just the relevant parts, called "Preguard," which I am working on now) and I would appreciate any help in determining what I am doing wrong.
    TIA,
    Jeff
    import javax.swing.JFrame;
    public class MailGenBuilder
    private String actions[] = { " ", "REMOVE", "STATUS", "SYNCH", "UPDATE" };
    private JFrame preguardFrame = new JFrame();
    public MailGenBuilder()
    public MailGen construct()
    // create the controls for preguardFrame
    JLabel preguardActionLabel = new JLabel( "SELECT ACTION" );
    preguardActionLabel.setHorizontalAlignment( JLabel.CENTER );
    // I'm not including the dimensions in this post (similar for a few lines down, also)
    preguardActionLabel.setPreferredSize( new Dimension( /*x, x*/ ) );
    JComboBox preguardActionComboBox = new JComboBox( actions );
    preguardActionComboBox.setBorder( BorderFactory.createLineBorder(
        Color.BLACK, 1 ) );
    preguardActionComboBox.setPreferredSize( new Dimension( /*x, x*/ ) );
    // create the SEND and CANCEL buttons
    JButton preguardSendButton = new JButton( "SEND STATUS" );
    preguardSendButton.setBackground( Color.white );
    preguardSendButton.setBorder( raisedBevel );
    JButton preguardCancelButton = new JButton( "CANCEL" );
    preguardCancelButton.setBackground( Color.white );
    preguardCancelButton.setBorder( raisedBevel );
    preguardFrame.getContentPane().setLayout( null );
    preguardFrame.getContentPane().add( preguardActionLabel );
    preguardFrame.getContentPane().add( preguardActionComboBox );
    preguardFrame.getContentPane().add( preguardSendButton );
    preguardFrame.getContentPane().add( preguardCancelButton );
    // add the various panels to the tabbed pane
    JTabbedPane pane = new JTabbedPane();
    // the exception is thrown on the next line
    pane.add( "PREGUARD", preguardFrame );
    pane.add( /*second pane*/ );
    pane.add( /*third pane*/ );
    pane.add( /*fourth pane*/ );

    You define preguardFrame as a JFrame which is a top level container, when you try to add it to a JTabbedFrame the above Exception is throw. Try making preguardFrame a JPanel.
    Also setting preguardFrame layout to null and then adding several components will probably not give you the result you want.
    Cheers
    DB

Maybe you are looking for

  • Minority Vendor Report

    Hi Guys, We have been trying to create this minority vendor report in SAP. I tried using FBL1N to get the report, but FBL1N has minority indicator in the selection screen but does not display the Min Indicator in the report. So, is there a way i can

  • URGENT - ora:processxslt Error

    I am using the ora:processxslt function in my assign and below is the following syntax: <copy> <from expression="ora:processXSLT('FormatDate.xsl',bpws:getVariableData('DFUReceieve_Read_InputVariable_1','OrderDemands','/ns6:OrderDemands/ns6:OrderDeman

  • Promise 378 SATA Raid question

    Can someone tell me if my SATA drives are setup correctly given the details below?  The only driver that works is the FastTrak 378 (not the SATA 378 driver).  I want to make sure I am taking full advantage of my SATA drives.  In the Promise setup it

  • Output determiation and crystal reports

    Hi all, I had a doubt regarding is it possible to integrate crystal reports with output determination. Regards, Nisha Divakaran

  • Metadata Extention for Dynamic Property Values

    We need to get dynamic values on XML Form based on the logged in user.  Implemented a Metadata Extension class for this purpose.  Followed the link in SDN to create the service and required classes : http://www.sdn.sap.com/irj/scn/index?rid=/library/