Reconstructing JPanel by an event

Hai there'
i have an app , when a button clicked it should add a set of components in row wise in JPanel which is in a JScrollPane.
I have problem that JPanel losts the previous components at each click.How could i make the Viewport to show components added previously.

The choice of layout manager can be crucial.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AddingComponents extends JPanel
    GridBagConstraints gbc;
    public AddingComponents()
        setLayout(new GridBagLayout());
        gbc = new GridBagConstraints();
        gbc.insets = new Insets(5,5,5,5);
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
    private JPanel getUIPanel()
        JButton add = new JButton("add components");
        add.addActionListener(new ActionListener()
            int count = 0;
            public void actionPerformed(ActionEvent e)
                for(int j = 0; j < 4; j++)
                    if((j + 1) % 4 == 0)
                        gbc.gridwidth = gbc.REMAINDER;
                    else
                        gbc.gridwidth = 1;
                    add(new JButton("button " + ++count), gbc);
                revalidate();
        JPanel panel = new JPanel();
        panel.add(add);
        return panel;
    public static void main(String[] args)
        AddingComponents ac = new AddingComponents();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(ac.getUIPanel(), "North");
        f.getContentPane().add(new JScrollPane(ac));
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • How can make Jpanel response click event?(help!)

    in a program i want to make jpanel response mouseclicked event, but jpanel class does not provide addActionListener(). through which way? i am able to arrive at the purpose! (create a new class extends jpanel, how to do?)
    thank a lot!!!

    Hello,
    have a look:import java.awt.Color;
    import java.awt.event.*;
    import javax.swing.*;
    public class ClickPanel extends JPanel implements MouseListener
         public static void main(String[]args)
              JFrame frame = new JFrame("Click-Panel");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.getContentPane().setLayout(null);
              frame.getContentPane().add(new ClickPanel());
              frame.setBounds(200,200,400,400);
              frame.setVisible(true);
         public ClickPanel()
              addMouseListener(this);
              setBounds(200,200,100,100);
              setBackground(Color.CYAN);
         public void mouseClicked(MouseEvent e)
              System.out.println("clicked");
         public void mouseEntered(MouseEvent e)
              System.out.println("entered");
              setBackground(Color.ORANGE);
         public void mouseExited(MouseEvent e)
              System.out.println("exited");
              setBackground(Color.CYAN);
         public void mousePressed(MouseEvent e)
              System.out.println("pressed");
         public void mouseReleased(MouseEvent e)
              System.out.println("released");
    }regards,
    Tim

  • Setting a JPanel on an event

    How would you set a blank JPanel to an existing JPanel extention class at an event?

    public class Test extends javax.swing.JFrame {
        public Test() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jPanel1 = new javax.swing.JPanel();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            jButton2.setText("jButton2");
            jButton3.setText("jButton3");
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 482, Short.MAX_VALUE)
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 371, Short.MAX_VALUE)
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton3)))
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jButton2)
                        .addComponent(jButton3))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
            pack();
        }// </editor-fold>
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
        * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Test().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JPanel jPanel1;
        // End of variables declaration
    }

  • Jpanel child action events

    I have a JPanel that i created which has an interface for choosing a date. I dropped the jpanel into an appointment book program im creating. It resides in the main frame of the appointment book program. The datechooser panel implements actionlistener, and changes the date member data field every time the user clicks on a different date, changes the month, etc...
    What i can't figure out, is how to tell when an event has taken place inside the datechooser panel from the appointment book frame. I need to update the appointment table in the appointment book frame every time the user changes the date by clicking on a new date insdide of the datechooser panel.

    Look at PropertyChangeListener in java.beans package. All swing components have the ability to fire property change ecents. Have your date chooser fire a property change event with the new date. Your frame can register as a PCL with the panel.
    There is also a java.swing.event.SwingPropertyChangeSupport class you might want to look at.
    Cheers
    DB

  • AddMouseListener disable events of bottom multiple non opaque JPanel

    Hi fellow developpers..
    I'm creating an application in which I'm using a JPanel containing multiple JPanel ( a layered system ) with some components laid on them. Everything works fine, events are properly traversing non opaque multiple JPanel, and I can access components of bottom most to top most JPanels.
    But when I'm adding MouseListeners on my non opaque JPanels, mouse events are no more going through them, only the top most one is receiving events.. my JPanels are still non opaque because I can see through them but mouse events are working as if they were opaque.
    Is there a trick to catch mouse events on non opaque JPanel without blocking event traversing ?
    Alexis.

    How about this?
             final ListView<Node> fileList = new ListView<Node>();
            fileList.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue<? extends Number> observableValue, Number oldv, Number newv) {
                    if (newv.intValue() == 4) {
                        fileList.getSelectionModel().select(oldv.intValue());
            });

  • How to fire mouse wheel events to parent container?

    Hi,
    When I create a JPanel (let's say jParent) inside a JScrollPane and this JPanel is larger than the current viewport I can use my mouse wheel to scroll the JPanel's containt without coding anything about that.
    But if I add another JPanel-derived component (let's say jChild) to the first JPanel, mouse wheel events are not received by the first JPanel when the mouse is over the new added child JPanel.
    How can I forward child's mouse wheel events to the first JPanel?
    If I use:
    jChild.addMouseWheelListener(jParent)I must implement a mouseWheelMoved() method in jParent that requires some code to work while it was doing it byitself before...
    Thanks in advance for any help :-)
    Regards,
    Lara.

    you have a mouseWheelListener added to jChild?
    if so, in the mouseWheelMoved code include this line
    jParent.dispatchEvent(mouseWheelEvent);//or to the scrollpane

  • Handling mouse events anywhere

    Hi,
    We have built an application with a Swing GUI and for automation and testing we would like to record all keyboard and mouse events to be able to play them afterwards.
    The keyboard events can be recorded easily with a KeyboardFocusManager but for the mouse events I still need a solution.
    The GUI consists of a JFrame containing several JPanels. When I add a MouseListener on the JFrame, its mousePressed and mouseReleased events are not called everytime I click somewhere on the frame. For example, when I click on a button inside one of the JPanels, the mouse event methods of the frame are not executed.
    Can somebody tell me how I can easily capture all mouse events in the GUI without adding MouseListeners in every JPanel??
    Thanks in advance...

    I know how to use the Robot class, that's not really the issue.
    What we are doing actually is writing keyboard and mouse events into a file.
    Afterwards we use the Robot class to playback the events in the file. This is no problem, I just don't know how I can easily intercept ALL mouse events in the GUI without adding mouseListeners in each component in the GUI.

  • Can JPanel know that its parent is closing?

    Hi,
    I was trying to find some way for a JPanel to know that its parent JFrame is closing. I know that the JFrame has a WindowEventListener, but does a JPanel have an event which tells it that the program is being closed?
    The reason is that in one application i have various JTables working with RMI. Whenever a client closes i would like to "unregister" them from the server. Ideally i would like to capture an event in the JPanel which tells me that the program is closing and i need to unregister my JTables from the RMI server.
    If there is no such solution I will have to put my code into the "windowClosing" event method in the JFrame instead, but i was hoping my JPanels can know when it closes.
    Thanks in advance.

    Hi
    I think there is no direct method to tell program is closing in JPanel. But u can create custom interface and call the interfact method in windowClosing event .

  • Help, trouble with JProgressBar

    Hi everybody
    I am having trouble implementing a JProgressBar. I am using SwingWorker and following the examples from the Swing tutorial but the task that the program is supposed to do is not doing it, it is like if the program stays in the Timer, and does not execute anything else. I am posting the simplified code that I am using.
    // GUI part (where thw progress bar is)
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class TaskGui extends JFrame
    private Container cp;
    private JTextField tf;
    private JLabel title;
    private JButton bGo;
    private JProgressBar progressBar;
    private Timer timer;
    private Task theTask;
    final private int SECOND= 1000;
    public TaskGui()
    super("Task Test");
    theTask= new Task();
    cp= getContentPane();
    cp.setLayout(new FlowLayout());
    title= new JLabel("Testing Progress Bar");
    // Initialize text fields
    tf= new JTextField(10);
    tf.setEditable(false);
    progressBar= new JProgressBar(0,100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    JPanel progPane= getProgBorderPane();
    // Event handler for "Go" button
    bGo= new JButton("Go");
    bGo.addActionListener( new ActionListener()
    public void actionPerformed(ActionEvent e)
    bGo.setEnabled(false);
    theTask.go();
    timer.start();
    cp.add(title);
    cp.add(tf);
    cp.add(progPane);
    cp.add(bGo);
    timer= new Timer(SECOND, new ActionListener()
    public void actionPerformed(ActionEvent e)
    progressBar.setValue(theTask.getPercentDone());
    out(theTask.getPercentDone() +" "+ theTask.getMaxCount() + "\n");
    if (theTask.finished())
    timer.stop();
    bGo.setEnabled(true);
    private JPanel getProgBorderPane()
    Border border= BorderFactory.createLoweredBevelBorder();
    TitledBorder tBorder= BorderFactory.createTitledBorder(
    border, "Progress...");
    JPanel bPane= new JPanel();
    bPane.setBorder(tBorder);
    progressBar= new JProgressBar(0,100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    bPane.add(progressBar);
    return bPane;
    private void out(String str) {System.out.print(str);}
    public static void main(String[] args)
    JFrame frame= new TaskGui();
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    frame.setSize(270,150);
    frame.setVisible(true);
    // Actual task
    public class Task
    private final static int SECOND= 1000;
    private final long maxCount= 10000;
    private long sofar;
    private boolean finished= false;
    public Task()
    sofar=0;
    public void go()
    final SwingWorker worker= new SwingWorker()
    public Object construct()
    return new RandCount();
    public int getPercentDone() { return (int)((sofar*100)/maxCount); }
    public long getMaxCount() { return maxCount; }
    public boolean finished() { return finished; }
    class RandCount
    public RandCount() {}
    public void work()
    do
    sofar += Math.random()*10;
    } while (sofar >= maxCount);
    finished= true;

    Check this out. I have posted a simplified application using JProgressBar.
    http://forum.java.sun.com/thread.jsp?forum=57&thread=138973

  • MediaPlayer and GlassPane

    I'm using MediaPlayer as a sort of screen saver with TouchScreen PC's, I want the player to stop when user's touch the screen. But I can't seem to get the Glasspane to intercept the mouse event.
    I am just trying to print out the location of the mouse clicks now to confirm it's there, but I'm getting nothing.
    class ScreenSaver extends JWindow{
    // snip some of setup
      getContentPane().add( myPlayer, BorderLayout.CENTER );
      setSize( Toolkit.getDefaultToolkit ().getScreenSize () );
      MyGlassPane myGlassPane = new MyGlassPane();
      setGlassPane(myGlassPane);
      myPlayer.setMediaLocation(new java.lang.String("file:///C:/videos/test.mpg"));
      myPlayer.start();
      setVisible(true);
    // build the glass pane
       class MyGlassPane extends Component implements MouseListener{
            public MyGlassPane(){
               setVisible(true);
               addMouseListener(this);
        public void mouseReleased(final java.awt.event.MouseEvent p1) {
        public void mouseEntered(final java.awt.event.MouseEvent p1) {
        public void mouseClicked(final java.awt.event.MouseEvent p1) {
          System.out.println( p1.getPoint() );
        // snip the rest of the mouse stuff

    Hey man I had the same problem than you!!!! with this code I solve it...all that you need is to add a Mouse listener to the component that controls the visual elements........It works so well!!!!
    import java.applet.*;
    import javax.swing.*;
    import java.awt.*;
    import java.net.*;
    import javax.media.*;
    import java.awt.event.*;
    import java.io.*;
    public class Video extends JWindow implements ControllerListener {
    Player player = null;
    Dimension dim=new Dimension();
    Component progressBar = null;
    private Base frame;
    private Frame f;
    private Glass glass;
    public Video() {     
         try {
         this.addWindowListener(new WindowAdapter(){
         public void windowClosing(WindowEvent e){                             
         hide();
         dispose();      
         activar();
         File file=new File("animacio.avi");     
         URL url = file.toURL();
         player = Manager.createPlayer(url);      
         player.addControllerListener(this);     
         crearBase();     
         dim=Toolkit.getDefaultToolkit().getScreenSize();
         setSize(dim.width,dim.height);                    
    setLocation(0,0);
    toFront();
    catch (Exception e) {
    JOptionPane.showMessageDialog(f,"Error al cargar la Presentaci�n","Error",JOptionPane.ERROR_MESSAGE);
    hide();
         dispose ();      
    crearBase();
    activar();
    public void play(){   
    player.start();
    show();      
    public synchronized void controllerUpdate(ControllerEvent event) {
    JPanel PMadre =new JPanel();
    try{
    if (event instanceof RealizeCompleteEvent) {
    Component comp;
    if ((comp = player.getVisualComponent()) != null){//comp=Visual lements->Video.avi
    //this is the crucial part!!!!!!!
    getContentPane().add ("Center", comp);
         comp.addMouseListener(new MouseAdapter(){
                        public void mouseClicked(MouseEvent e){                                              
                        System.out.println("Ok");
                        hide();
                        dispose ();      
                   activar();
    if ((comp = player.getControlPanelComponent()) != null){}
              validate();
    if (event instanceof EndOfMediaEvent)
    player.stop();
    hide();
         dispose ();
    //crearBase();
    //frame.show();
    activar();
    }catch (Exception e) {
    JOptionPane.showMessageDialog(f,"Error al cargar la Presentaci�n","Error",JOptionPane.ERROR_MESSAGE);
    hide();
         dispose ();      
    crearBase();
    //frame.show();      
    activar();
         public void crearBase(){
         Dimension dim=new Dimension();
         dim=Toolkit.getDefaultToolkit().getScreenSize();          
              if(dim.width==800)
                        frame=new Base("Brait",0,0);          
              frame.setSize(800,600);
    if(dim.width>800&&dim.width<=1024)//&&dim.height==768||dim.width>1024&&dim.height>=768)
                        frame=new Base("Brait",100,50);          
              frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());          
    if(dim.width>1024)
                        frame=new Base("Brait",200,150);          
              frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());          
    frame.setIconImage(Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("pswd.gif")));//Icono del Frame           
    frame.setResizable(false);
    frame.setLocation(0,0);
    //frame.show();      
         public void activar(){          
    frame.show();
    }//final classe

  • JButtons and JTextfields conflicting

    Hey again,
    I have a JPanel which contains a JTextfield, a JButton and a JLabel.
    Basically, the user sticks a word in the JTextfield, presses enter, and the word gets displayed by the JLabel.
    At the moment I have the Jpanel listening for events from both the JTextField and the JButton, which means that clicking the button generates a getActionCommand()and the text on the JButton gets stuck on the JLabel- as if the word had been entered in the JTextField.
    It's easy enough to get something else to listen to the button to get round this, but I just wondered if there's a way of allowing the JPanel to listen to them both without having this conflict (just so that it's easier for me to keep track of everything!)
    Any suggestions muchly appreciated !!

    I just saw your posting date and could not help noticing that you posted this message in January. But I hope others can benefit from our feedbacks. First of all, you do not need to add a listener to a JPanel. You could add listeners to your other components and add them all to the panel.
    And in your textField you need to add actionListener and tell the label to setText the text it receives from the textField. Make sure that your components do not listener to only one actionListener.
    The following should be in your actionPerformed method:
    String string = textField.getText();
    label.setText(string);//the text from the textField.
    Hope this helps
    [email protected]

  • The JPanel no longer gets a focus event after upgrading java version

    I have started looking at an application, which I haven't developed myself. It is a Swing application which runs as a standalone application. It is currently running on JRE 1.4.1, but for many reasons we would like to upgrade (to 1.5.0).
    During one of the actions that the users make is that he goes through a number of screens filling in details and then goes to the next screen. This has been done through having a JTabbedPane with six tabs. Each tab is a JPanel with various content.
    At each page the user presses a button, which (among other things) sets the selected Index of the JTabbedPane to the next tab. The JPanel that is attached to the tab has a FocusListener, which does various load actions when the JPanel receives focus.
    Now to the problem: In version 1.4.1 (up to and including version 1.4.1_07) these actions actually triggered the FocusListener event and ran the focusGained method as intended. Starting from 1.4.2 (and any 1.5 version I have tested) this event does not occur any longer (no code change, simply changing the JRE). My conclusion is that either the JPanel no longer gets focus or the event simply does not get triggered even though it should. What I can't figure out is why, what really happens and finally even more important, how do I solve this.
    Any help is appreciated. The code is quite extensive so it does not quite fit in here, but I will provide snippets as requested.

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5089436
    "Evaluation" section will give you more info.
    basically, you have to set a requestFocusInWindow(), but it needs to be
    wrapped in a SwingUtilities.invokeLater(..), or, if that fails to work, inside a
    timer, setRepeats(false), about 150ms.
    From memory, it is only the timer that will work with the JTabbedPane, but
    with newer versions, the SwingUtilities.invokelater() might now work

  • Event handling in JMenu in JPanel

    Hi,
    I'm writing a small register program GUI. I have a problem with ActionListener in JMenu. I wrote a JPanel which creates a JMenu and that works just fine. The problem is that id doesn't give any event signals. I have another class which impelemets ActionListener and it works fine with JButton (another panel for buttons), but not with JMenu.
    Below is the JPanel for JMenu and Application which implements the ActionListener. Do you see anything wrong? I really can't imagine why I cannot get the action signals. JPanel is defined in JFrame as it should be. Have you got any ideas?
    Regards,
    Marko
    class MenuPanel extends JPanel {
         protected JMenuBar menuBar;
         protected JMenu menu;
         protected JMenuItem loadRegister;
         protected JMenuItem saveRegister;
         protected JMenuItem information;
         protected JMenuItem quit;
         public MenuPanel(Application application) {
              menuBar = new JMenuBar();          
              menu = new JMenu("Tiedosto");     
              loadRegister = new JMenuItem("Lataa");
              loadRegister.addActionListener(application);
              saveRegister = new JMenuItem("Talleta");
              saveRegister.addActionListener(application);
              information = new JMenuItem("Tietoja");
              information.addActionListener(application);
              quit = new JMenuItem("Lopeta");                    quit.addActionListener(application);
              menu.add(loadRegister);
              menu.add(saveRegister);
              menu.addSeparator();
              menu.add(information);
              menu.add(quit);          
              menuBar.add(menu);
    class Application implements ActionListener {     
         // Define CardPanel
         private CardPanel cardPanel;
         // Define linked list for cards
         private CardList cardList = null;
         // Constructor. Initializes cardPanel and cardList
         public Application(CardPanel cardPanelRefrence) {
              cardPanel = cardPanelRefrence;
              cardList = new CardList();
         public void actionPerformed(ActionEvent action) {
              String actionPerformed = action.getActionCommand();
              if (actionPerformed.equals("Lataa")) {
                   load();          
              if (actionPerformed.equals("Talleta")) {
                   save();          
              if (actionPerformed.equals("Tietoja")) {
                   info();          
              if (actionPerformed.equals("Lopeta")) {
                   System.exit(0);
    // Continues with the methods...

    Well, I found the answer. Heh, quite easy one but it took a while before I found it..
    Just if you ever have similar problem. The problem was that in my JFrame I didn't create an object of class (Application) which implement s the ActionListener before using it as a reference in creating JPanel object. Quite confusing explanation, but here the code. This code was in my JFrame which was not included in this question.
    private Application application;
    private MenuPanel menuPanel;
    application = new Application(cardPanel, rightInfoPanel);
    menuPanel = new MenuPanel(application);
    These two were introduced other way round, so that variable "application" was null. What a problem in fact.. :)
    - Marko

  • Coalescing events from multiple components in a JPanel

    Hi,
    I've got a JPanel based form with several components (mostly JTextField) and I'd like to be able to have component events bubble up to the parent JPanel. By comparison to MFC, if I have a dialog box with several controls all of the control events will continue to percolate upwards until they are handled. Is there any such possibility with Swing?
    Ideally I would like it if all component events were routed to a single listener in the parent JPanel, all I really need to do (initially) is set a boolean to note that a change may have been made. Do I have to explicitly set a handler for each component or is there way to automagically have the parent to catch the events from its child components?
    Thanks!
    jam

    Thanks jvaudry, this is kinda what I suspected. It seems somewhat cumbersome to have to set up a listener for each of the many JTextField's in my form but definitely wrapping all of that up in a class is a good way to go. I'm pretty new to Swing and usually when something seems harder than it should it's a sure sign that I just don't know how to do it right :)
    I may try an altogether different approach just for curiousity's sake. I'm thinking of adding a method to the parent JPanel that will iterate all of its text fields and create a checksum of their combined contents. The idea is that I will compute the checksum once after populating the form and then later to see if any of the fields have changed. A simple notion that may not turn out to be so simple once I get to coding, but it's worth a try.
    Thanks!
    jam

  • Question on program structure about event handling in nested JPanels in GUI

    Hi All,
    I'm currently writing a GUI app with a wizard included in the app. I have one class that acts as a template for each of the panels in the wizard. That class contains a JPanel called contentsPanel that I intend to put the specific contents into. I also want the panel contents to be modular so I have a couple of classes for different things, e.g. name and address panel, etc. these panels will contain checkboxes and the like that I want to event listeneres to watch out for. Whats the best way of implementing event handling for panel within panel structure? E.g for the the checkbox example,would it be a good idea to have an accessor method that returns the check book object from the innerclass/panel and use an addListener() method on the returned object in the top level class/panel. Or is it better to have the event listeners for those objects in the same class? I would appreciate some insight into this?
    Regards!

    MyMainClass.main(new String[] { "the", "arguments" });
    // or, if you defined your main to use varags (i.e. as "public static void main(String... args)") then you can just use
    MyMainClass.main("the", "arguments");But you should really extract your functionality out of the main method into meaningful classes and methods and just use those from both your console code and your GUI code.

Maybe you are looking for

  • ITunes Will Not Open and I have Tried Everything Posted...

    Please Help! I have downloaded the latest version, deleted it and tried again. I have deleted folders, turned off my Norton protection and still no go. Can anyone here help me from this 7 hour nightmare? I had an iPod and iTunes on this computer befo

  • Itunes gift cards...

    hi i bought a gift card, i entered the code, bought 2 songs, then wanted to buy a game, and it's like i have no money left on the card. i can see how much is left on left side of my account name but i can't use it! can anybody help me..i sent a email

  • Release a worklist thru t-code AR31

    Hi When I am trying to release a worklist thru t-code AR31. I am getting "No Administrator found for the task" message. I follow below mentioned procedure. 1. AR01 -> Give your company code -> and the asset numbers Now press F8 to execute the same. 2

  • Virus in the database

    Is it possible that Oracle database can be infected with virus ? If yes, how do you clean it up ? null

  • Mac mini wont read disc drive

    Just got an audio interface for garage band however mac mini wont read the disc drive to load software. It has worked in the past. Tryed an audio cd and its not reading that either.