Problems with CardLayout

Does anyone know how/if I should be overriding getLayoutAlignmentX (of LayoutManager2) in order to get the cards (panels) in my CardLayout to appear somewhere other than centred in the panel.
My problem is that I don't seem to be able to alter the layout such that when the card is switched in it appears at the left of the panel in which it is contained.

Overriding the layout manager should never be your first step.
All a CardLayout does is make one of its contained panels visible. The layout manager may resize the panel, in which case it's the panel's own layout manager that's centering the content.
The easiest (but ugliest) solution is simply to put another panel in the hierarchy, using FlowLayout. Something like this (uncompiled, untested):
    JPanel myCardPanel = new JPanel(new CardLayout());
    JPanel holder = new JPanel(new FlowLayout(FlowLayout.LEADING)));
    JPanel myRealPanel = // however you get it
    holder.add(myRealPanel);
    myCardPanel.add(holder,  "Top");As I said, this is a really hackish solution. A better solution is to arrange the layout on your real panel so that it can expand without changing the position of its components. Or lock its maximum size ot its preferred size.

Similar Messages

  • Java Applet Panel problems with CardLayout

    Hi, I have a problem a I have been stucked for 2 days.
    I created 3 Panels to use with CardLayout. I would switch between those 3 panels depending on user interaction. I have some textfields and text areas on the 2nd and 3rd Panel. On the 1st panel, I would like to use g.drawstring to write some stuff on that panel, but the words would be blocked off if it goes to where the components are on the other panels.
    Thanks.

    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    public class CardTest extends Applet
        Panel panel;
        CardLayout cards;
        public void init()
        {   cards = new CardLayout();
            panel = new Panel(cards);
            panel.add("one", new GraphicPanel());
            panel.add("two", getPanel("panel two"));
            panel.add("three", getPanel("panel three"));
            setLayout(new BorderLayout());
            add(getNavPanel(), "North");
            add(panel);
        private Panel getNavPanel()
            final Button
                last = new Button("last"),
                next = new Button("next");
            ActionListener l = new ActionListener()
                public void actionPerformed(ActionEvent e)
                    Button button = (Button)e.getSource();
                    if(button == last)
                        cards.previous(panel);
                    if(button == next)
                        cards.next(panel);
            last.addActionListener(l);
            next.addActionListener(l);
            Panel panel = new Panel();
            panel.add(last);
            panel.add(next);
            return panel;
        private Panel getPanel(String s)
            Panel panel = new Panel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weighty = 1.0;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(new Button("button"), gbc);
            panel.add(new TextArea(s, 8, 16), gbc);
            return panel;
        public static void main(String[] args)
            Applet applet = new CardTest();
            Frame f = new Frame();
            f.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent e)
                    System.exit(0);
            f.add(applet);
            f.setSize(400,400);
            f.setLocation(200,200);
            applet.init();
            f.setVisible(true);
    class GraphicPanel extends Panel
        Font font;
        String text;
        final int PAD = 25;
        public GraphicPanel()
            font = new Font("lucida bright regular", Font.PLAIN, 22);
            text = "Hello World";
        public void paint(Graphics g)
            super.paint(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int w = getWidth();
            int h = getHeight();
            int dia = Math.min(w,h)/6;
            g2.setPaint(Color.blue);
            g2.drawLine(PAD, PAD, w - PAD, PAD);
            g2.drawLine(PAD, h - PAD, w - PAD, h - PAD);
            g2.setPaint(Color.green.darker());
            g2.drawOval(w/2 - dia/2, h*2/3, dia, dia);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            float width = (float)font.getStringBounds(text, frc).getWidth();
            LineMetrics lm = font.getLineMetrics(text, frc);
            float x = (w - width)/2;
            float y = (h + lm.getHeight())/2 -lm.getDescent();
            g2.setPaint(Color.black);
            g2.drawString(text, x, y);
    }

  • Problem with CardLayout

    I ve got a JFrame object and i want to put in it a JMenuBar and a CardLayout that contains two JPanel.
    1. Is it possible to do that
    3. how to do it.(I have already created my JMenuBar in my JFrame)

    Ok this is my source code.
    my problem is to insert a cardlayout it dosen't seem to work.
    Can you help me please.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.TitledBorder ;
    public class Frame1 extends javax.swing.JFrame
         Panel_Moteur jPanel1 = new Panel_Moteur();
         javax.swing.JMenuBar jMenuBar1 = new javax.swing.JMenuBar();
         javax.swing.JMenu jMenuFichier = new javax.swing.JMenu();
         javax.swing.JSeparator jMenuFichierSeparator1 = new javax.swing.JSeparator();
         javax.swing.JMenuItem jMenuFichierQuitter = new javax.swing.JMenuItem();
         javax.swing.JMenu jMenuConfiguration = new javax.swing.JMenu();
         javax.swing.JMenuItem jMenuConfigurationMoteur = new javax.swing.JMenuItem();
         javax.swing.JSeparator jMenuConfigurationSeparator1 = new javax.swing.JSeparator();
         javax.swing.JMenuItem jMenuConfigurationHoraire = new javax.swing.JMenuItem();
         javax.swing.JMenu jMenuProgrammes = new javax.swing.JMenu();
         javax.swing.JMenuItem jMenuProgrammesAjouter = new javax.swing.JMenuItem();
         javax.swing.JMenuItem jMenuProgrammesModifier = new javax.swing.JMenuItem();
         javax.swing.JMenuItem jMenuProgrammesSupprimer = new javax.swing.JMenuItem();
         javax.swing.JSeparator jMenuProgrammesSeparator1 = new javax.swing.JSeparator();
         javax.swing.JMenuItem jMenuProgrammesVisualiser = new javax.swing.JMenuItem();
         javax.swing.JMenu jMenuAcquisition = new javax.swing.JMenu();
         javax.swing.JMenuItem jMenuAcquisitionCapture = new javax.swing.JMenuItem();
         javax.swing.JMenu jMenuReconstitution = new javax.swing.JMenu();
         javax.swing.JMenuItem jMenuReconstitutionImageGlobale = new javax.swing.JMenuItem();
         JPanel cards = new JPanel();
         CardLayout cardlayout = new CardLayout() ;
         public Frame1() {
         public void initComponents() throws Exception
              cards.setSize(new java.awt.Dimension(930, 830));
              cards.setLocation(new java.awt.Point(0, 40));
    cards.setLayout(cardlayout);
              cards.add(jPanel1,"t");
              jMenuBar1.setVisible(true);
              jMenuFichier.setVisible(true);
              jMenuFichier.setText("Fichier");
              jMenuFichierSeparator1.setVisible(true);
              jMenuFichierQuitter.setVisible(true);
              jMenuFichierQuitter.setText("Quitter");
              jMenuConfiguration.setVisible(true);
              jMenuConfiguration.setText("Configuration");
              jMenuConfigurationMoteur.setVisible(true);
              jMenuConfigurationMoteur.setText("Moteur");
              jMenuConfigurationSeparator1.setVisible(true);
              jMenuConfigurationHoraire.setVisible(true);
              jMenuConfigurationHoraire.setText("Horaire");
              jMenuProgrammes.setVisible(true);
              jMenuProgrammes.setText("Programmes");
              jMenuProgrammesAjouter.setVisible(true);
              jMenuProgrammesAjouter.setText("Ajouter");
              jMenuProgrammesModifier.setVisible(true);
              jMenuProgrammesModifier.setText("Modifier");
              jMenuProgrammesSupprimer.setVisible(true);
              jMenuProgrammesSupprimer.setText("Supprimer");
              jMenuProgrammesSeparator1.setVisible(true);
              jMenuProgrammesVisualiser.setVisible(true);
              jMenuProgrammesVisualiser.setText("Visualiser");
              jMenuAcquisition.setVisible(true);
              jMenuAcquisition.setText("Acquisition");
              jMenuAcquisitionCapture.setVisible(true);
              jMenuAcquisitionCapture.setText("Capture");
              jMenuReconstitution.setVisible(true);
              jMenuReconstitution.setText("Reconstitution");
              jMenuReconstitutionImageGlobale.setVisible(true);
              jMenuReconstitutionImageGlobale.setText("Image Globale");
              setLocation(new java.awt.Point(150, 70));
              setResizable(false);
              setJMenuBar(jMenuBar1);
              getContentPane().setLayout(null);
              setTitle("ProjetAutoroot.Frame1");
              jMenuBar1.add(jMenuFichier);
              jMenuBar1.add(jMenuConfiguration);
              jMenuBar1.add(jMenuProgrammes);
              jMenuBar1.add(jMenuAcquisition);
              jMenuBar1.add(jMenuReconstitution);
              jMenuFichier.add(jMenuFichierSeparator1);
              jMenuFichier.add(jMenuFichierQuitter);
              jMenuConfiguration.add(jMenuConfigurationMoteur);
              jMenuConfiguration.add(jMenuConfigurationSeparator1);
              jMenuConfiguration.add(jMenuConfigurationHoraire);
              jMenuProgrammes.add(jMenuProgrammesAjouter);
              jMenuProgrammes.add(jMenuProgrammesModifier);
              jMenuProgrammes.add(jMenuProgrammesSupprimer);
              jMenuProgrammes.add(jMenuProgrammesSeparator1);
              jMenuProgrammes.add(jMenuProgrammesVisualiser);
              jMenuAcquisition.add(jMenuAcquisitionCapture);
              jMenuReconstitution.add(jMenuReconstitutionImageGlobale);
              getContentPane().add(cards);
              setSize(new java.awt.Dimension(941, 923));
              jMenuFichierQuitter.addActionListener(new java.awt.event.ActionListener() {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        jMenuFichierQuitterActionPerformed(e);
              jMenuConfigurationMoteur.addActionListener(new java.awt.event.ActionListener() {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        jMenuConfigurarionMoteurActionPerformed(e);
              addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        thisWindowClosing(e);
         private boolean mShown = false;
         public void addNotify() {
              super.addNotify();
              if (mShown)
                   return;
              // resize frame to account for menubar
              JMenuBar jMenuBar = getJMenuBar();
              if (jMenuBar != null) {
                   int jMenuBarHeight = jMenuBar.getPreferredSize().height;
                   Dimension dimension = getSize();
                   dimension.height += jMenuBarHeight;
                   setSize(dimension);
              mShown = true;
         // Close the window when the close box is clicked
         void thisWindowClosing(java.awt.event.WindowEvent e) {
              setVisible(false);
              dispose();
              System.exit(0);
         public void jMenuFichierQuitterActionPerformed(java.awt.event.ActionEvent e) {
              setVisible(false);
              dispose();
              System.exit(0);
         public void jMenuConfigurarionMoteurActionPerformed (java.awt.event.ActionEvent e)
              System.out.println("bonjour") ;
              CardLayout cl = (CardLayout)(cards.getLayout());
              cl.show(cards,"t");
         public void jRadioButton1StateChanged(javax.swing.event.ChangeEvent e) {
         public void jRadioButton2StateChanged(javax.swing.event.ChangeEvent e) {
         public void jRadioButton9StateChanged(javax.swing.event.ChangeEvent e) {
    }

  • Focus issue with CardLayout (Java 2 SDK, Standard Edition 1.4.0_01)

    I am having an issue with focus and CardLayout with Java 2 SDK, Standard Edition 1.4.0_01. I have created a small sample application to illustrate my problem. In general, I am trying to create a "Wizard" that the user will enter information and then press a "Next" button to proceed to the next step.
    When the first card is displayed, the focus is on the first text field as expected.
    When I go to the next card by clicking "Next", the focus is not on the text field that has requested it (through the requestFocusInWindow method). The focus is on the "Cancel" button, which is the next component to receive focus after the "Next" button on that panel. I do notice that if I use my mouse to bring focus to the window the text field will gain focus.
    Similarly, when I proceed to the last card, the focus is not on the "Finish" button until the mouse moves over the window.
    Is there something I am doing wrong or is there a bug with focus and CardLayout?
    One other problem I have noticed is that the buttons no longer respond to the "Enter" key press and instead respond to the space bar. Any suggestions as to why this is the case?
    Thanks,
    S.L.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CardWindow extends JFrame implements ActionListener {
    public CardWindow() {       
    setTitle("Focus Problems with CardLayout");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    cards = new JPanel();
    cardLayout = new CardLayout();
    cards.setLayout(cardLayout);
    cards.add(createFirstNamePanel(), "FirstNamePanel");
    cards.add(createLastNamePanel(), "LastNamePanel");
    cards.add(createFullNamePanel(), "FullNamePanel");
    getContentPane().add(cards,BorderLayout.CENTER);
    getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
    resetButtonPanel();
    pack();
    private JPanel createFirstNamePanel() {
    JPanel panel = new JPanel();
    JLabel lblDescriptionProjectName = new JLabel("Please enter your first name:");
    txtFirstName = new JTextField(20);
    panel.add(lblDescriptionProjectName);
    panel.add(txtFirstName);
    return panel;
    private JPanel createLastNamePanel() {
    JPanel panel = new JPanel();
    JLabel lblDescriptionProjectName = new JLabel("Please enter your last name:");
    txtLastName = new JTextField(20);
    panel.add(lblDescriptionProjectName);
    panel.add(txtLastName);
    return panel;
    private JPanel createFullNamePanel(){
    JPanel panel = new JPanel();
    lblFullName = new JLabel();
    resetTextOnFullNamePanel();
    panel.add(lblFullName);
    return panel;
    private JPanel createButtonPanel() {
    buttonPanel = new JPanel();
    btnPrevious = new JButton("< " + "Back");
    btnPrevious.setMnemonic('B');
    btnPrevious.addActionListener(this);
    btnNext = new JButton("Next" + " >");
    btnNext.setMnemonic('N');
    btnNext.addActionListener(this);
    btnCancel = new JButton("Cancel");
    btnCancel.setMnemonic('C');
    btnCancel.addActionListener(this);
    btnFinish = new JButton("Finish");
    btnFinish.setMnemonic('F');
    btnFinish.addActionListener(this);
    buttonPanel.add(btnPrevious);
    buttonPanel.add(btnNext);
    buttonPanel.add(btnCancel);
    buttonPanel.add(btnFinish);
    return buttonPanel;
    private void resetTextOnFullNamePanel(){
    lblFullName.setText("Your name is: " + getFirstName() + " " + getLastName());
    private void resetButtonPanel(){
    Component c[] = buttonPanel.getComponents();
    for(int i = 0; i < c.length; i++){
    c.setVisible(false);
    switch(iWizardStep){
    case FIRSTNAMEPANEL:
    btnPrevious.setVisible(true);
    btnNext.setVisible(true);
    btnCancel.setVisible(true);
    break;
    case LASTNAMEPANEL:
    btnPrevious.setVisible(true);
    btnNext.setVisible(true);
    btnCancel.setVisible(true);
    break;
    case FULLNAMEPANEL:
    btnFinish.setVisible(true);
    break;
    buttonPanel.validate();
    public void actionPerformed(ActionEvent e) {
    Object object = e.getSource();
    if (object == btnNext) {           
    btnNextPressed();
    } else if (object == btnPrevious) {           
    btnPreviousPressed();
    } else if (object == btnFinish) {
    System.exit(0);
    } else if (object == btnCancel) {
    System.exit(0);
    private void btnNextPressed() {       
    switch (iWizardStep) {
    case FIRSTNAMEPANEL:
    setFirstName(txtFirstName.getText());
    break;
    case LASTNAMEPANEL:
    setLastName(txtLastName.getText());
    resetTextOnFullNamePanel();
    break;
    iWizardStep++;
    resetButtonPanel();
    this.cardLayout.next(this.cards);
    switch (iWizardStep) {             
    case LASTNAMEPANEL:
    txtLastName.requestFocusInWindow();
    break;
    case FULLNAMEPANEL:
    btnFinish.requestFocusInWindow();
    break;
    private void btnPreviousPressed() {
    iWizardStep--;
    resetButtonPanel();
    this.cardLayout.previous(this.cards);
    public void setFirstName(String value) {
    firstName = value;
    public String getFirstName() {
    return firstName;
    public void setLastName(String value) {
    lastName = value;
    public String getLastName() {
    return lastName;
    public static void main (String[] args) {
    CardWindow c = new CardWindow();
    c.show();
    private CardLayout cardLayout;
    private JPanel cards, buttonPanel;
    private JTextField txtLastName, txtFirstName;
    private JLabel lblFullName;
    private JButton btnNext, btnPrevious, btnCancel, btnFinish;
    private String firstName = "";
    private String lastName = "";
    private int iWizardStep = 0;
    private static final int FIRSTNAMEPANEL = 0;
    private static final int LASTNAMEPANEL = 1;
    private static final int FULLNAMEPANEL = 2;

    Manfred,
    Thanks for your reply. I tried requestFocus() and it gives the same results. Also Sun's 1.4.0 API (http://java.sun.com/j2se/1.4/docs/api/) mentions the following with respect to the requestFocus() method in the JComponent class:
    Because the focus behavior of this method is platform-dependent, developers are strongly encouraged to use requestFocusInWindow when possible.
    That is why I used requestFocusInWindow.
    S.L.

  • Problems with actionListeners on CardLayout...Help Please

    I'm having a problem with my clear button on card2 in my code. When pressed it will not clear the data, and I don't see anything wrong with the code. Am I overlooking something? Please take a look at the long code I have posted and let me know what is going on with this if you could.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class BankGUI implements ItemListener
         JPanel cards;
         final String main = "Main menu";
         final String addCust = "Add a new customer";
         final String upCust = "Change a current customer's information";
         final String addAcct = "Add a new account";
         final String withdrawl = "Withdrawl monies from an account";
         final String deposit = "Deposit monies into an account";
         final String report = "Run report to show all accounts";
         JComboBox cb;
         JRadioButton savings, checking;
         JCheckBox yes, no;
         JLabel firstNameLabel, lastNameLabel, addressLabel, cityLabel, stateLabel,
              phoneLabel, customerNumbLabel, accountNumbLabel, depositLabel,
              accountTypeLabel, savingsProLabel, balanceLabel, withdrawlLabel;
         JTextField firstNameField, lastNameField, addressField, cityField,
              stateField, phoneField, customerNumbField, accountNumbField,
              depositField, accountTypeField, balanceField, withdrawlField;
         JButton submit1, submit3, submit4, submit5, submit6, clear, logoff, run, find,
               delete, update, runReport;
         JFrame f;
         String firstName;
         String lastName;
         String address;
         String city;
         String state;
         String phoneNumber;
         String customerNumber;
         Controller cont;
         Customer cust;
         public void addComponent(Container pane)
              JPanel comboBoxPane = new JPanel();
              String comboBoxItems[] = {main, addCust, upCust, addAcct,
                   withdrawl, deposit, report};
              JComboBox cb = new JComboBox(comboBoxItems);
              cb.setEditable(false);
              cb.addItemListener(this);
              comboBoxPane.add(cb);
              JPanel card1 = new JPanel(); //main menu
              logoff = new JButton("Logoff");
              logoff.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent l)
                        cont = new Controller();
                        cont.wrapUp();
              card1.add(logoff); //end main menu
              JPanel card2 = new JPanel(new GridLayout(0,4,1,1)); //add customer
              firstNameLabel = new JLabel("First Name:", SwingConstants.RIGHT);
              card2.add(firstNameLabel);
              firstNameField = new JTextField("", 10);
              card2.add(firstNameField);
              lastNameLabel = new JLabel("Last Name:", SwingConstants.RIGHT);
              card2.add(lastNameLabel);
              lastNameField = new JTextField("", 10);
              card2.add(lastNameField);
              addressLabel = new JLabel("Address:", SwingConstants.RIGHT);
              card2.add(addressLabel);
              addressField = new JTextField("", 10);
              card2.add(addressField);
              cityLabel = new JLabel("City:", SwingConstants.RIGHT);
              card2.add(cityLabel);
              cityField = new JTextField("", 10);
              card2.add(cityField);
              stateLabel = new JLabel("State:", SwingConstants.RIGHT);
              card2.add(stateLabel);
              stateField = new JTextField("", 10);
              card2.add(stateField);
              phoneLabel = new JLabel("Phone Number:", SwingConstants.RIGHT);
              card2.add(phoneLabel);
              phoneField = new JTextField("", 10);
              card2.add(phoneField);
              customerNumbLabel = new JLabel("Customer Number (SSN):", SwingConstants.RIGHT);
              card2.add(customerNumbLabel);
              customerNumbField = new JTextField("", 10);
              card2.add(customerNumbField);
              card2.add(new JLabel(""));
              card2.add(new JLabel(""));
              card2.add(new JLabel(""));
              submit1 = new JButton("Submit");
              /*submit1.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent s1)
                        firstName = firstNameField.getText();
                        lastName = lastNameField.getText();
                        address = addressField.getText();
                        city = cityField.getText();
                        state = stateField.getText();
                        phoneNumber = phoneField.getText();
                        customerNumber = customerNumbField.getText();
                        Customer cust = new Customer(firstName, lastName, address, city, state, phoneNumber, customerNumber);
                        System.out.println(cust.getFirstName());
              card2.add(submit1);
              clear = new JButton("Clear");
              clear.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent c)
                        firstNameField.setText("");
                        lastNameField.setText("");
                        addressField.setText("");
                        cityField.setText("");
                        stateField.setText("");
                        phoneField.setText("");
                        customerNumbField.setText("");
                        firstNameField.requestFocus();
              card2.add(clear); //end add customer
              JPanel card3 = new JPanel(new GridLayout(0,4,1,1)); //update customer
              card3.add(new JLabel(""));
              customerNumbLabel = new JLabel("Customer Number (SSN):", SwingConstants.RIGHT);
              card3.add(customerNumbLabel);
              customerNumbField = new JTextField("", 10);
              card3.add(customerNumbField);
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              find = new JButton("Find");
              card3.add(find);
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              card3.add(new JLabel(""));
              firstNameLabel = new JLabel("First Name:", SwingConstants.RIGHT);
              card3.add(firstNameLabel);
              firstNameField = new JTextField("", 10);
              card3.add(firstNameField);
              lastNameLabel = new JLabel("Last Name:", SwingConstants.RIGHT);
              card3.add(lastNameLabel);
              lastNameField = new JTextField("", 10);
              card3.add(lastNameField);
              addressLabel = new JLabel("Address:", SwingConstants.RIGHT);
              card3.add(addressLabel);
              addressField = new JTextField("", 10);
              card3.add(addressField);
              cityLabel = new JLabel("City:", SwingConstants.RIGHT);
              card3.add(cityLabel);
              cityField = new JTextField("", 10);
              card3.add(cityField);
              stateLabel = new JLabel("State:", SwingConstants.RIGHT);
              card3.add(stateLabel);
              stateField = new JTextField("", 10);
              card3.add(stateField);
              phoneLabel = new JLabel("Phone Number:", SwingConstants.RIGHT);
              card3.add(phoneLabel);
              phoneField = new JTextField("", 10);
              card3.add(phoneField);
              card3.add(new JLabel(""));
              submit3 = new JButton("Save Changes");
              card3.add(submit3); //end update customer
              JPanel card4 = new JPanel(new GridLayout(0,4,1,1)); //add account
              customerNumbLabel = new JLabel("Customer Number (SSN):", SwingConstants.RIGHT);
              card4.add(customerNumbLabel);
              customerNumbField = new JTextField("", 10);
              card4.add(customerNumbField);
              card4.add(new JLabel(""));
              card4.add(new JLabel(""));
              accountNumbLabel = new JLabel("Account Number:", SwingConstants.RIGHT);
              card4.add(accountNumbLabel);
              accountNumbField = new JTextField("", 10);
              card4.add(accountNumbField);
              card4.add(new JLabel(""));
              card4.add(new JLabel(""));
              accountTypeLabel = new JLabel("Account Type:", SwingConstants.RIGHT);
              card4.add(accountTypeLabel);
              savings = new JRadioButton("Savings");
              card4.add(savings);
              checking = new JRadioButton("Checking");
              card4.add(checking);
              card4.add(new JLabel(""));
              depositLabel = new JLabel("Deposit Amount:", SwingConstants.RIGHT);
              card4.add(depositLabel);
              depositField = new JTextField("", 10);
              card4.add(depositField);
              card4.add(new JLabel(""));
              card4.add(new JLabel(""));
              submit4 = new JButton("Submit");
              card4.add(submit4);//end add account
              JPanel card5 = new JPanel(new GridLayout(0,4,1,1)); //withdrawl
              accountNumbLabel = new JLabel("Account Number:", SwingConstants.RIGHT);
              card5.add(accountNumbLabel);
              accountNumbField = new JTextField("", 10);
              card5.add(accountNumbField);
              card5.add(new JLabel(""));
              card5.add(new JLabel(""));
              withdrawlLabel = new JLabel("Withdrawl Amount:", SwingConstants.RIGHT);
              card5.add(withdrawlLabel);
              withdrawlField = new JTextField("", 10);
              card5.add(withdrawlField);
              card5.add(new JLabel(""));
              card5.add(new JLabel(""));
              submit5 = new JButton("Submit");
              card5.add(submit5);//end withdrawl
              JPanel card6 = new JPanel(new GridLayout(0,4,1,1)); //deposit
              accountNumbLabel = new JLabel("Account Number:", SwingConstants.RIGHT);
              card6.add(accountNumbLabel);
              accountNumbField = new JTextField("", 10);
              card6.add(accountNumbField);
              card6.add(new JLabel(""));
              card6.add(new JLabel(""));
              depositLabel = new JLabel("Deposit Amount:", SwingConstants.RIGHT);
              card6.add(depositLabel);
              depositField = new JTextField("", 10);
              card6.add(depositField);
              card6.add(new JLabel(""));
              card6.add(new JLabel(""));
              submit6 = new JButton("Submit");
              card6.add(submit6);//end deposit
              JPanel card7 = new JPanel(); //run report
              card7.add(new JLabel(""));
              runReport = new JButton("Run Report");
              card7.add(runReport);//end report
              cards = new JPanel(new CardLayout());
              cards.add(card1, main);
              cards.add(card2, addCust);
              cards.add(card3, upCust);
              cards.add(card4, addAcct);
              cards.add(card5, withdrawl);
              cards.add(card6, deposit);
              cards.add(card7, report);
              pane.add(comboBoxPane, BorderLayout.PAGE_START);
              pane.add(cards);
         public void itemStateChanged(ItemEvent evt)
              CardLayout cl = (CardLayout)(cards.getLayout());
              cl.show(cards, (String)evt.getItem());
         public void createGUI()
              f = new JFrame("Bank of Sean");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              BankGUI bankGUI = new BankGUI();
              bankGUI.addComponent(f.getContentPane());
              f.pack();
              f.setVisible(true);
         public static void main(String[] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        BankGUI bankGUI = new BankGUI();
                        bankGUI.createGUI();
    }

    You have a generic problem that is illustrated by looking at your 'firstNameField'. You define just one 'firstNameField' variable and then allocated a value several times so that the content of 'firstNameField' add to card2 using
    card2.add(firstNameField);
    does not refer to the same object as is used in your action listener
    firstNameField.setText("");
    because in your card3 section you overwrite the original content ot the reference.
    You can fix this by sharing a Document e.g.
    Document doc = firstNameField.getDocument();
    firstNameField = new JTextField(doc, "", 10);
    card3.add(firstNameField);
    for each time a new field is reqired.

  • Problem with JTextArea or is it my code, Help!!!

    Hi,
    I am going crazy. I am sending a message to a JTextArea and I get some very wierd things happening? I really need help because this is driving me crazy. Please see the following code to see my annotations for the problems. Has anyone else experienced problems with this component?
    Thanks,
    Steve
    // THIS IS THE CLASS THAT HANDLES ALL OF THE WORK
    public class UpdateDataFields implements ActionListener {     // 400
         JTextArea msg;
         JPanel frameForCardPane;
         CardLayout cardPane;
         TestQuestionPanel fromRadio;
         public UpdateDataFields( JTextArea msgout ) {     // 100
              msg = msgout;
          }       // 100
         public void actionPerformed(ActionEvent evt) {     // 200
              String command = evt.getActionCommand();
              String reset = "Test of reset.";
              try{
                   if (command.equals("TestMe")){     // 300
                        msg.append("\nSuccessful");
                        Interface.changeCards();
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
              try{
                   if (command.equals("ButtonA")){     // 300
    // WHEN I CALL BOTH OF THE FOLLOWING METHODS THE DISPLAY WORKS
    // BUT THE CHANGECARDS METHOD DOES NOT WORK.  WHEN I COMMENT OUT
    // THE CALL TO THE DISPLAYMESSAGE METHOD THEN THE CHANGECARDS WORKS
    // FINE.  PLEASE THE INTERFACE CLASS NEXT.
                        Interface.changeCards();
                        Interface.displayMessage("test of xyz");
                        }     // 300
              catch(Exception e){
                   e.printStackTrace();
         }     // 200
    }     // 400
    // END OF UPDATEDATAFIELS  END END END
    public class Interface extends JFrame {     // 300
         static JPanel frameForCardPane;
         static CardLayout cardPane;
         static JTextArea msgout;
         TestQuestionPanel radio;
         Interface () {     // 100
              super("This is a JFrame");
            setSize(800, 400);  // width, height
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // set-up card layout
              cardPane = new CardLayout();
              frameForCardPane = new JPanel();     // for CardLayout
              frameForCardPane.setLayout(cardPane);     // set the layout to cardPane = CardLayout
              TestQuestionPanel cardOne = new TestQuestionPanel("ABC", "DEF", msgout, radio);
              TestQuestionPanel cardTwo = new TestQuestionPanel("GHI", "JKL", msgout, radio);
              frameForCardPane.add(cardOne, "first");
              frameForCardPane.add(cardTwo, "second");
              // end set-up card layout
              // set-up main pane
              // declare components
              msgout = new JTextArea( 8, 40 );
              ButtonPanel commandButtons = new ButtonPanel(msgout);
              JPanel pane = new JPanel();
              pane.setLayout(new GridLayout(2, 4, 5, 15));             pane.setBorder(BorderFactory.createEmptyBorder(30, 20, 10, 30));
              pane.add(frameForCardPane);
                 pane.add( new JScrollPane(msgout));
                 pane.add(commandButtons);
              msgout.append("Successful");
              setContentPane(pane);
              setVisible(true);
         }     // 100
    // HERE ARE THE METHODS THAT SHOULD HANDLE THE UPDATING
         static void changeCards() {     // 200
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
         }     // 200
         static void displayMessage(String test) {     // 200
                   String reset = "Test of reset.";
                   String passMessage = test;
                   cardPane.next(frameForCardPane);
                   System.out.println("Calling methods works!");
                   msgout.append("\n"+ test);
         }     // 200
    }     // 300

    Hi,
    I instantiate it in this class. Does that change your opinion or the advice you gave me? Please help!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class CardLayoutQuestionsv2 {
        public static void main(String[] arguments) {
            JFrame frame = new Interface();
            frame.show();
    }

  • A problem with threads

    I am trying to implement some kind of a server listening for requests. The listener part of the app, is a daemon thread that listens for connections and instantiates a handling daemon thread once it gets some. However, my problem is that i must be able to kill the listening thread at the user's will (say via a sto button). I have done this via the Sun's proposed way, by testing a boolean flag in the loop, which is set to false when i wish to kill the thread. The problem with this thing is the following...
    Once the thread starts excecuting, it will test the flag, find it true and enter the loop. At some point it will LOCK on the server socket waiting for connection. Unless some client actually connects, it will keep on listening indefinatelly whithought ever bothering to check for the flag again (no matter how many times you set the damn thing to false).
    My question is this: Is there any real, non-theoretical, applied way to stop thread in java safely?
    Thank you in advance,
    Lefty

    This was one solution from the socket programming forum, have you tried this??
    public Thread MyThread extends Thread{
         boolean active = true;          
         public void run(){
              ss.setSoTimeout(90);               
              while (active){                   
                   try{                       
                        serverSocket = ss.accept();
                   catch (SocketTimeoutException ste){
                   // do nothing                   
         // interrupt thread           
         public void deactivate(){               
              active = false;
              // you gotta sleep for a time longer than the               
              // accept() timeout to make sure that timeout is finished.               
              try{
                   sleep(91);               
              }catch (InterruptedException ie){            
              interrupt();
    }

  • Problem with Threads and a static variable

    I have a problem with the code below. I am yet to make sure that I understand the problem. Correct me if I am wrong please.
    Code functionality:
    A timer calls SetState every second. It sets the state and sets boolean variable "changed" to true. Then notifies a main process thread to check if the state changed to send a message.
    The problem as far I understand is:
    Assume the timer Thread calls SetState twice before the main process Thread runs. As a result, "changed" is set to true twice. However, since the main process is blocked twice during the two calls to SetState, when it runs it would have the two SetState timer threads blocked on its synchronized body. It will pass the first one, send the message and set "changed" to false since it was true. Now, it will pass the second thread, but here is the problem, "changed" is already set to false. As a result, it won't send the message even though it is supposed to.
    Would you please let me know if my understanding is correct? If so, what would you propose to resolve the problem? Should I call wait some other or should I notify in a different way?
    Thanks,
    B.D.
    Code:
    private static volatile boolean bChanged = false;
    private static Thread objMainProcess;
       protected static void Init(){
            objMainProcess = new Thread() {
                public void run() {
                    while( objMainProcess == Thread.currentThread() ) {
                       GetState();
            objMainProcess.setDaemon( true );
            objMainProcess.start();
        public static void initStatusTimer(){
            if(objTimer == null)
                 objTimer = new javax.swing.Timer( 1000, new java.awt.event.ActionListener(){
                    public void actionPerformed( java.awt.event.ActionEvent evt){
                              SetState();
        private static void SetState(){
            if( objMainProcess == null ) return;
            synchronized( objMainProcess ) {
                bChanged = true;
                try{
                    objMainProcess.notify();
                }catch( IllegalMonitorStateException e ) {}
        private static boolean GetState() {
            if( objMainProcess == null ) return false;
            synchronized( objMainProcess ) {
                if( bChanged) {
                    SendMessage();
                    bChanged = false;
                    return true;
                try {
                    objMainProcess.wait();
                }catch( InterruptedException e ) {}
                return false;
        }

    Thanks DrClap for your reply. Everything you said is right. It is not easy to make them alternate since SetState() could be called from different places where the state could be anything else but a status message. Like a GREETING message for example. It is a handshaking message but not a status message.
    Again as you said, There is a reason I can't call sendMessage() inside setState().
    The only way I was able to do it is by having a counter of the number of notifies that have been called. Every time notify() is called a counter is incremented. Now instead of just checking if "changed" flag is true, I also check if notify counter is greater than zero. If both true, I send the message. If "changed" flag is false, I check again if the notify counter is greater than zero, I send the message. This way it works, but it is kind of a patch than a good design fix. I am yet to find a good solution.
    Thanks,
    B.D.

  • Problem with threads running javaw

    Hi,
    Having a problem with multi thread programming using client server sockets. The program works find when starting the the application in a console using java muti.java , but when using javaw multi.java the program doesnt die and have to kill it in the task manager. The program doesnt display any of my gui error messages either when the server disconnect the client. all works find in a console. any advice on this as I havent been able to understand why this is happening? any comment would be appreciated.
    troy.

    troy,
    Try and post a minimum code sample of your app which
    does not work.
    When using javaw, make sure you redirect the standard
    error and standard output streams to file.
    Graeme.Hi Graeme,
    I dont understand what you mean by redirection to file? some of my code below.
    The code works fine under a console, code is supposed to exit when the client (the other server )disconnects. the problem is that but the clientworker side of the code still works. which under console it doesnt.
    public class Server{
    ServerSocket aServerSocket;
    Socket dianosticsSocket;
    Socket nPortExpress;
    ClientListener aClientListener;
    LinkedList queue = new LinkedList();
    int port = 0;
    int clientPort = 0;
    String clientName = null;
    boolean serverAlive = true;
    * Server constructor generates a server
    * Socket and then starts a client threads.
    * @param aPort      socket port of local machine.
    public Server(int aPort, String aClientName, int aClientPort){
    port = aPort;
    clientName = aClientName;
    clientPort = aClientPort;
    try{
    // create a new thread
    aServerSocket = new ServerSocket(port) ;
    // connect to the nPortExpress
    aClientListener = new ClientListener(InetAddress.getByName(clientName), clientPort, queue,this);
    // aClientListener.setDaemon(true);
    aClientListener.start();
    // start a dianostic port
    DiagnosticsServer aDiagnosticsServer = new DiagnosticsServer(port,queue,aClientListener);
    // System.out.println("Server is running on port " + port + "...");
    // System.out.println("Connect to nPort");
    catch(Exception e)
    // System.out.println("ERROR: Server port " + port + " not available");
    JOptionPane.showMessageDialog(null, (e.toString()),"ERROR: Server port " + port + " not available", JOptionPane.ERROR_MESSAGE);
    serverAlive = false;
    System.exit(1);
    while(serverAlive&&aClientListener.hostSocket.isConnected()){
    try{
    // connect the client
    Socket aClient = aServerSocket.accept();
    //System.out.println("open client connection");
    //System.out.println("client local: "+ aClient.getLocalAddress().toString());
    // System.out.println("client localport: "+ aClient.getLocalPort());
    // System.out.println("client : "+ aClient.getInetAddress().toString());
    // System.out.println("client port: "+ aClient.getLocalPort());
    // make a new client thread
    ClientWorker clientThread = new ClientWorker(aClient, queue, aClientListener, false);
    // start thread
    clientThread.start();
    catch(Exception e)
    //System.out.println("ERROR: Client connection failure");
    JOptionPane.showMessageDialog(null, (e.toString()),"ERROR: Client connection failure", JOptionPane.ERROR_MESSAGE);
    }// end while
    } // end constructor Server
    void serverExit(){
         JOptionPane.showMessageDialog(null, "Server ","ERROR: nPort Failure", JOptionPane.ERROR_MESSAGE);
         System.exit(1);
    }// end class Server
    *** connect to another server
    public class ClientListener extends Thread{
    InetAddress hostName;
    int hostPort;
    Socket hostSocket;
    BufferedReader in;
    PrintWriter out;
    boolean loggedIn;
    LinkedList queue;      // reference to Server queue
    Server serverRef; // reference to main server
    * ClientListener connects to the host server.
    * @param aHostName is the name of the host eg server name or IP address.
    * @param aHostPort is a port number of the host.
    * @param aLoginName is the users login name.
    public ClientListener(InetAddress aHostName, int aHostPort,LinkedList aQueue,Server aServer)      // reference to Server queue)
    hostName = aHostName;
    hostPort = aHostPort;
    queue = aQueue;
    serverRef = aServer;      
    // connect to the server
    try{
    hostSocket = new Socket(hostName, hostPort);
    catch(IOException e){
    //System.out.println("ERROR: Connection Host Failed");
    JOptionPane.showMessageDialog(null, (e.toString()),"ERROR: Connection to nPort Failed", JOptionPane.ERROR_MESSAGE);     
    System.exit(0);
    } // end constructor ClientListener
    ** multi client connection server
    ClientWorker(Socket aSocket,LinkedList aQueue, ClientListener aClientListener, boolean diagnostics){
    queue = aQueue;
    addToQueue(this);
    client = aSocket;
    clientRef = aClientListener;
    aDiagnostic = diagnostics;
    } // end constructor ClientWorker
    * run method is the main loop of the server program
    * in change of handle new client connection as well
    * as handle all messages and errors.
    public void run(){
    boolean alive = true;
    String aSubString = "";
    in = null;
    out = null;
    loginName = "";
    loggedIn = false;
    while (alive && client.isConnected()&& clientRef.hostSocket.isConnected()){
    try{
    in = new BufferedReader(new InputStreamReader(client.getInputStream()));
    out = new PrintWriter(new OutputStreamWriter(client.getOutputStream()));
    if(aDiagnostic){
    out.println("WELCOME to diagnostics");
    broadCastDia("Connect : diagnostics "+client.getInetAddress().toString());
    out.flush();
    else {       
    out.println("WELCOME to Troy's Server");
    broadCastDia("Connect : client "+client.getInetAddress().toString());
         out.flush();
    String line;
    while(((line = in.readLine())!= null)){
    StringTokenizer aStringToken = new StringTokenizer(line, " ");
    if(!aDiagnostic){
    broadCastDia(line);
    clientRef.sendMessage(line); // send mesage out to netExpress
    out.println(line);
    out.flush();
    else{
    if(line.equals("GETIPS"))
    getIPs();
    else{
    clientRef.sendMessage(line); // send mesage out to netExpress
    out.println(line);
    out.flush();
    } // end while
    catch(Exception e){
    // System.out.println("ERROR:Client Connection reset");
                             JOptionPane.showMessageDialog(null, (e.toString()),"ERROR:Client Connection reset", JOptionPane.ERROR_MESSAGE);     
    try{
    if(aDiagnostic){
    broadCastDia("Disconnect : diagnostics "+client.getInetAddress().toString());
    out.flush();
    else {       
    broadCastDia("Disconnect : client "+client.getInetAddress().toString());
         out.flush();
    // close the buffers and connection;
    in.close();
    out.close();
    client.close();
    // System.out.println("out");
    // remove from list
    removeThreadQueue(this);
    alive = false;
    catch(Exception e){
    // System.out.println("ERROR: Client Connection reset failure");
    JOptionPane.showMessageDialog(null, (e.toString()),"ERROR: Client Connection reset failure", JOptionPane.ERROR_MESSAGE);     
    }// end while
    } // end method run
    * method run - Generates io stream for communicating with the server and
    * starts the client gui. Run also parses the input commands from the server.
    public void run(){
    boolean alive = true;
    try{
    // begin to life the gui
    // aGuiClient = new ClientGui(hostName.getHostName(), hostPort, loginName, this);
    // aGuiClient.show();
    in = new BufferedReader(new InputStreamReader(hostSocket.getInputStream()));
    out = new PrintWriter(new OutputStreamWriter(hostSocket.getOutputStream()));
    while (alive && hostSocket.isConnected()){
    String line;
    while(((line = in.readLine())!= null)){
    System.out.println(line);
    broadCast(line);
    } // end while
    } // end while
    catch(Exception e){
    //     System.out.println("ERRORa Connection to host reset");
    JOptionPane.showMessageDialog(null, (e.toString()),"ERROR: Connection to nPort reset", JOptionPane.ERROR_MESSAGE);
    try{
    hostSocket.close();
         }catch(Exception a){
         JOptionPane.showMessageDialog(null, (a.toString()),"ERROR: Exception", JOptionPane.ERROR_MESSAGE);
    alive = false;
    System.exit(1);
    } // end method run

  • Problem with threads and camera.

    Hi everybody!
    I've a problem with taking snapshot.
    I would like to display a loading screen after it take snapshot ( sometimes i
    have to wait few seconds after i took snapshot. Propably photo is being taken in time where i have to wait).
    I was trying to use threads but i didn't succeed.
    I made this code:
    display.setCurrent(perform);               
            new Thread(new Runnable(){
                public void run() {               
                    while((!performing.isShown()) && (backgroundCamera.isShown())){
                        Thread.yield();
                    notifyAll();
            }).start();
            new Thread(new Runnable(){
                public void run() {
                    try {
                        this.wait();                   
                    } catch(Exception e) {
                        exceptionHandler(e);
                    photo = camera.snapshot();                               
                    display.setCurrent(displayPhoto);
            }).start();This code is sometimes showing performing screen but sometimes no.
    I don't know why. In my opinion performing.isShown() method isn't working correctly.
    Does anyone have some idea how to use threads here?

    Hi,
    I've finally managed to work this fine.
    The code:
           Object o = new Object();
           display.setCurrent(perform);               
            new Thread(new Runnable(){
                public void run() {               
                    while(!performing.isShown()){
                        Thread.yield();
                   synchronized(o) {
                      o.notify();
            }).start();
            new Thread(new Runnable(){
                public void run() {
                    try {
                        synchronized(o) {
                           o.wait(1);
                    } catch(Exception e) {
                        exceptionHandler(e);
                    photo = camera.snapshot();                               
                    display.setCurrent(displayPhoto);
            }).start();

  • Problem with threads hanging

    We have a problem where our application stops responding after a few days of usage. Things will for fine for a day or two, and then pretty quickly threads will start getting hung up, usually in places where they are allocating memory
    We are running WebLogic 8.1 SP2 on Sun JDK 1.4.2_04 on Solaris 8 using the alternate threading model and the -server hotspot vm. We are running pretty much the same code that we had no problems with under WebLogic 6.1 SP4 and Sun JDK 1.3.1.
    A thread dump usually shows that some or all of our execute threads are in the state "waiting for monitor entry" even though they are not currently waiting on any java locks. Here is a sample thread from the thread dump (we have ~120 threads so I don't want to post the full dump).
    =============================================================================================
    "ExecuteThread: '8' for queue: 'itgCrmWarExecutionQueue'" daemon prio=5 tid=0x005941d0 nid=0x2c waiting for monitor entry [c807f000..c807fc28]
    at java.lang.String.substring(String.java:1446)
    at java.lang.String.substring(String.java:1411)
    at weblogic.servlet.internal.ServletRequestImpl.getRelativeUri(ServletRequestImpl.java:1872)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3492)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
    =============================================================================================
    String.java line 1446 for this jdk allocates a new String object, and all the other threads in this state also are creating new objects or arrays, etc.
    We've done a pstack on this process when it's in this state, and the threads that are in the "waiting for monitor entry" that look like they're allocating memory are all waiting on the same lwp_mutex_lock with some allocation method that's calling into the native TwoGenerationCollectorPolicy.mem_allocate_work (see pstack output below for the same thread as in the thread dump above)
    =============================================================================================
    ----------------- lwp# 44 / thread# 44 --------------------
    ff31f364 lwp_mutex_lock (e3d70)
    fee92384 __1cNObjectMonitorGenter26MpnGThread__v_ (5000, 525c, 5000, 50dc, 4800, 4af0) + 2d8
    fee324d4 __1cSObjectSynchronizerKfast_enter6FnGHandle_pnJBasicLock_pnGThread__v_ (c807f65c, c807f7d4, 5941d0, 0, 35d654, fee328ec) + 68
    fee32954 __1cQinstanceRefKlassZacquire_pending_list_lock6FpnJBasicLock__v_ (c807f7d4, ff170000, d4680000, 4491d4, fee1bc2c,
    0) + 78
    fee3167c __1cPVM_GC_OperationNdoit_prologue6M_i_ (c807f7bc, 4400, ff170000, 2d2b8, 4a6268, c807fa18) + 38
    fee2e0b0 __1cIVMThreadHexecute6FpnMVM_Operation__v_ (c807f7bc, 963a8, 0, 0, 1, 0) + 90
    fed2c2a4 __1cbCTwoGenerationCollectorPolicyRmem_allocate_work6MIii_pnIHeapWord__ (962c0, ff1c29ec, ff1c297c, ff131a26, 4800, 4998) + 160
    fed22940 __1cNinstanceKlassRallocate_instance6MpnGThread__pnPinstanceOopDesc__ (ee009020, 5941d0, 15ca581, 3647f0, 4a6268, c807f8c8) + 180
    fed34928 __1cLOptoRuntimeFnew_C6FpnMklassOopDesc_pnKJavaThread__v_ (ee009018, 5941d0, 0, 0, 0, 0) + 28
    fa435a58 ???????? (ee009018, e86de, 15ca4de, 50dc, 5941d0, c807f9c8)
    fb36f9a4 ???????? (0, d412ccd8, ee046c28, ff170000, 0, 0)
    fad8b278 ???????? (ee046c28, d6000c90, ee046530, 8, db8e8450, c807f9e8)
    fad62abc ???????? (d412ccd8, ee046530, d6000c90, ee3bfa38, 8, c807fa18)
    fa4b3c38 ???????? (c807fb9c, 0, f2134700, fa415e50, 8, c807faa8)
    fa40010c ???????? (c807fc28, c807fe90, a, ee9e1e20, 4, c807fb40)
    fed5d48c __1cJJavaCallsLcall_helper6FpnJJavaValue_pnMmethodHandle_pnRJavaCallArguments_pnGThread__v_ (c807fe88, c807fcf0, c807fda8, 5941d0, 5941d0, c807fd00) + 27c
    fee4b784 __1cJJavaCallsMcall_virtual6FpnJJavaValue_nLKlassHandle_nMsymbolHandle_4pnRJavaCallArguments_pnGThread__v_ (ff170000, 594778, c807fd9c, c807fd98, c807fda8, 5941d0) + 164
    fee5e8dc __1cJJavaCallsMcall_virtual6FpnJJavaValue_nGHandle_nLKlassHandle_nMsymbolHandle_5pnGThread__v_ (c807fe88, c807fe84, c807fe7c, c807fe74, c807fe6c, 5941d0) + 6c
    fee6fc74 __1cMthread_entry6FpnKJavaThread_pnGThread__v_ (5941d0, 5941d0, 838588, 594778, 306d10, fee69254) + 128
    fee6927c __1cKJavaThreadDrun6M_v_ (5941d0, 2c, 40, 0, 40, 0) + 284
    fee6575c _start   (5941d0, fa1a1600, 0, 0, 0, 0) + 134
    ff3758c0 lwpstart (0, 0, 0, 0, 0, 0)
    =============================================================================================
    Also when it's having this problem, the "VM Thread" is always using a lot of processor time. We did a couple of pstacks today while it was having this problem, and this thread was stuck in the ONMethodSweeper.sweep for over 15 minutes when we finally killed the server.
    From the thread dump:
    "VM Thread" prio=5 tid=0x000e2d20 nid=0x2 runnable
    From the first pstack:
    =============================================================================================
    ----------------- lwp# 2 / thread# 2 --------------------
    fed40c04 __1cXvirtual_call_RelocationIparse_ic6FrpnICodeBlob_rpC5rppnHoopDesc_pi_nNRelocIterator__ (42a2f4, fa5fa46d, ffffffff, fc4ffcb8, 42a2f4, 42a324) + 124
    fed46318 __1cKCompiledIC2t5B6MpnKRelocation__v_ (42a2f0, fc4ffd24, fc4ffd4c, e802, 0, 6) + 38
    fed90c38 __1cHnmethodVcleanup_inline_caches6M_v_ (fa5f7f88, fa608940, 1, 0, fa400000, 6) + 1ac
    fede18b4 __1cONMethodSweeperFsweep6F_v_ (2cf38, 0, ffffffff, ff1cf1fc, ff1c66e8, fede1d44) + 1b0
    fede1e6c __1cUSafepointSynchronizeFbegin6F_v_ (2cf38, ff1ba138, 5000, 50dc, 5000, 525c) + 248
    feef1fd4 __1cIVMThreadEloop6M_v_ (4400, 4000, 4324, 4000, 42b0, 3800) + 3d4
    feef1ae4 __1cIVMThreadDrun6M_v_ (e2d20, 2, 40, 0, 40, 0) + 8c
    fee6575c _start   (e2d20, ff270200, 0, 0, 0, 0) + 134
    ff3758c0 lwpstart (0, 0, 0, 0, 0, 0)
    =============================================================================================
    Second pstack
    =============================================================================================
    ----------------- lwp# 2 / thread# 2 --------------------
    fed41180 __1cXvirtual_call_RelocationIparse_ic6FrpnICodeBlob_rpC5rppnHoopDesc_pi_nNRelocIterator__ (0, ff1b9664, ffffffff, fc4ffcb8, a6f2cc, fc4ffbd0) + 6a0
    fed46318 __1cKCompiledIC2t5B6MpnKRelocation__v_ (a6f2c8, fc4ffd24, fc4ffd4c, e802, 0, 6) + 38
    fed90c38 __1cHnmethodVcleanup_inline_caches6M_v_ (faded4c8, fadf2c80, 1, 0, fa400000, 6) + 1ac
    fede18b4 __1cONMethodSweeperFsweep6F_v_ (2cf38, 0, ffffffff, ff1cf1fc, ff1c66e8, fede1d44) + 1b0
    fede1e6c __1cUSafepointSynchronizeFbegin6F_v_ (2cf38, ff1ba138, 5000, 50dc, 5000, 525c) + 248
    feef1fd4 __1cIVMThreadEloop6M_v_ (4400, 4000, 4324, 4000, 42b0, 3800) + 3d4
    feef1ae4 __1cIVMThreadDrun6M_v_ (e2d20, 2, 40, 0, 40, 0) + 8c
    fee6575c _start   (e2d20, ff270200, 0, 0, 0, 0) + 134
    ff3758c0 lwpstart (0, 0, 0, 0, 0, 0)
    =============================================================================================
    Has anyone ever seen anything like this? I'm trying to figure out if this is caused by something we're doing, or something relating to our environment and jvm options. Any ideas?

    Thanks for the reply - I'm testing our app with the +UseConcMarkSweepGC now in our test environment to make sure it doesn't cause any problems there.  Unfortunately the only place we've had this problem is on the production server, so it's extra difficult debugging this. 
    We're using the following memory options:
    -ms512m -mx512m -XX:NewSize=128m -XX:PermSize=192m -XX:MaxNewSize=128m -XX:MaxPermSize=192m -XX:SurvivorRatio=8and the following debugging options, as we've also been seeing OutOfMemoryErrors ( see http://forum.java.sun.com/thread.jsp?forum=37&thread=522354&tstart=45&trange=15 )
    -verbosegc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGCBTW, which c++filt version and options are you using? Our Solaris boxes only seem to have the GNU version installed. I was trying to run that on some of the other stack traces and wasn't getting anywhere, and didn't know if because it was GNU version wouldn't work on something compiled with the Sun compiler.
    Thanks!
    --Andy                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem with threads and ProgressMonitor

    Dear Friends:
    I have a little problem with a thread and a ProgressMonitor. I have a long time process that runs in a thread (the thread is in an separate class). The thread has a ProgressMonitor that works fine and shows the tasks progress.
    But I need deactivate the main class(the main class is the user interface) until the thread ends.
    I use something like this:
    LongTask myTask=new LongTask();
    myTask.start();
    myTask.join();
    Now, the main class waits for the task to end, but the progress monitor don`t works fine: it shows only the dialog but not the progress bar.
    What's wrong?

    Is the dialog a modal dialog? This can block other UI updates.
    In general, you should make sure that it isn't modal, and that your workThread has a fairly low priority so that the UI can do its updating

  • Problem with threads and/or memory

    I'm developing an application where there are 3 threads. One of them sends a request to the other, and if the 2nd can't answer it, it sends it to the 3rd (similar to CPU -> CACHE -> MEMORY). When i run the program with 1000-10.000 requests, no problem occurs. When i run it with 300.000-1.000.000 requests, it sometimes hangs. Is this a problem with the garbage collector, or should it be related to the threads mecanism.
    (note: eache thread is in execution using a finite state machine)

    i had been running the program inside Netbeans.
    Running the jar using the command line outside
    Netbeans i have no more problems... Does Netbeans use
    it's own JVM?Depends how you set it up, but look under the options. There are settings for the compiler and jvm that it uses.

  • Installation problem with NW'04 SR1: database connection failed

    Hi all,
    while installing NW '04 SR1 on Windows Server 2003 SP1 and MS SQL Server 2000 SP4 I ran into an error related to the database connection. While performing the step "Load Java Database content" SAPinst crashes with the message
    com.sap.sql.log.OpenSQLException: Could not load class com.ddtek.jdbc.sqlserver.SQLServerDriver.
    The connection to the SLQ Server with e.g. the Query Analyzer is OK. I had a problem with this installation setup before (have a look at the corresponding <a href="https://forums.sdn.sap.com/thread.jspa?threadID=338638&tstart=0">thread</a> ), the JDBC drivers where missing on the installation master but after copying them in the right direction the installation went on with no problem up to this point...
    Has anybody an idea what could have happened here? Is this maybe a problem connected to the one I recently had
    Below I attached the sapinst.log and jload.log with more detailed messages.
    sapinst.log ###########
    INFO 2007-03-12 22:06:24
    Working directory changed to C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_~1\ONE_HOST.
    INFO 2007-03-12 22:06:24
    Output of D:\Java/bin/java.exe '-classpath' './sharedlib/antlr.jar;./sharedlib/exception.jar;./sharedlib/jddi.jar;./sharedlib/jload.jar;./sharedlib/logging.jar;./sharedlib/offlineconfiguration.jar;./sharedlib/opensqlsta.jar;./sharedlib/tc_sec_secstorefs.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\base.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\util.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\sqlserver.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\spy.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jce_export.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jsse.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_smime.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_ssl.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/w3c_http.jar' '-showversion' '-Xmx512m' 'com.sap.inst.jload.Jload' '-sec' 'WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key' '-dataDir' 'S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP' '-job' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML' '-log' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log' is written to the logfile C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_~1\ONE_HOST/jload.java.log.
    WARNING 2007-03-12 22:06:26
    Execution of the command "D:\Java/bin/java.exe '-classpath' './sharedlib/antlr.jar;./sharedlib/exception.jar;./sharedlib/jddi.jar;./sharedlib/jload.jar;./sharedlib/logging.jar;./sharedlib/offlineconfiguration.jar;./sharedlib/opensqlsta.jar;./sharedlib/tc_sec_secstorefs.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\base.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\util.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\sqlserver.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\spy.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jce_export.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jsse.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_smime.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_ssl.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/w3c_http.jar' '-showversion' '-Xmx512m' 'com.sap.inst.jload.Jload' '-sec' 'WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key' '-dataDir' 'S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP' '-job' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML' '-log' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log'" finished with return code 1. Output:
    java version "1.4.2_13"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_13-b06)
    Java HotSpot(TM) Client VM (build 1.4.2_13-b06, mixed mode)
    12.03.2007 22:06:25 com.sap.inst.jload.Jload main
    INFO: Jload -sec WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key -dataDir S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP -job C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML -log C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log
    12.03.2007 22:06:26 com.sap.inst.jload.Jload main
    SCHWERWIEGEND: couldn't connect to DB
    com.sap.sql.log.OpenSQLException: Could not load class com.ddtek.jdbc.sqlserver.SQLServerDriver.
    ERROR 2007-03-12 22:06:26
    CJS-20065  Execution of JLoad tool 'D:\Java/bin/java.exe '-classpath' './sharedlib/antlr.jar;./sharedlib/exception.jar;./sharedlib/jddi.jar;./sharedlib/jload.jar;./sharedlib/logging.jar;./sharedlib/offlineconfiguration.jar;./sharedlib/opensqlsta.jar;./sharedlib/tc_sec_secstorefs.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\base.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\util.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\sqlserver.jar;D:\usr\sap/WPT/JC10/j2ee\jdbc\spy.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jce_export.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_jsse.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_smime.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/iaik_ssl.jar;D:/usr/sap/WPT/SYS/global/security/lib/tools/w3c_http.jar' '-showversion' '-Xmx512m' 'com.sap.inst.jload.Jload' '-sec' 'WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key' '-dataDir' 'S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP' '-job' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML' '-log' 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log'' aborts with returncode 1. Check 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log' and 'C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.java.log' for more information.
    jload.log ###########
    12.03.07 22:06 com.sap.inst.jload.Jload main
    INFO: Jload -sec WPT,jdbc/pool/WPT,D:\usr\sap\WPT\SYS\global/security/data/SecStore.properties,D:\usr\sap\WPT\SYS\global/security/data/SecStore.key -dataDir S:/D51030724\J2EE_OSINDEP\J2EE-ENG/JDMP -job C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/IMPORT.XML -log C:\PROGRA1\SAPINS1\NW04SR1\WEBAS_1\ONE_HOST/jload.log
    12.03.07 22:06 com.sap.inst.jload.Jload main
    SEVERE: couldn't connect to DB
    com.sap.sql.log.OpenSQLException: Could not load class com.ddtek.jdbc.sqlserver.SQLServerDriver.
    Best regards,
    Bernd

    Hello Kairat,
    Please follow the below mentioned guide to install it.
    Check all the parameters to set and run pre requisite checker before starting installation.
    Keep in mind that before starting any SAP installation you should always run prerequisite checker.
    https://websmp205.sap-ag.de/instguides --> SAP Netweaver -->SAP Netweaver 7.0 -- > Installations --> EHP2
    Regards,
    Amit Barnawal

  • My app store wont let me download apps, says the card is expired and theres a problem with previous purchase can someone help me pls?

    My app store wont let me download apps, asks me to update my payment details then says theres a problem with previous purchase and card is expired which is untrue someone help me pls

    This is a User to User Forum...
    See Here for
    Mac Apps Store Customer Service
    http://www.apple.com/support/mac/app-store/contact.html?form=account
    iTunes Customer Service Contact
    http://www.apple.com/support/itunes/contact.html

Maybe you are looking for

  • Save report on client side in three tier architecture

    Hi, We have a 3 tier 10g R2 Application server installed on Unix. We want to generate and save report directly to a location on client machine. But when we try to do that report is saved in server and not on client machine. Can anyone help in this re

  • Problem with Web Dynpro Theme in 2004s ABAP Sneak Preview

    Hi ! Working on the Web Dynpro for ABAP 2004s Sneak Preview I encountered a problem in applying a web Dynpro theme via the URL-parameter sap-cssurl. I tried the following URL: http://hostname:8000/sap/bc/webdynpro/sap/webdynproapp?sap-cssurl=http://h

  • Using Apple DVD PLayer...

    I can't seem to open my Video_TS file so that I can view my home movie before I burn a copy. In fact, my disk image file of the movie is inaccessible in the program (file name is pale grey shade under 'Open DVD Media'). Does anyone know how to remedy

  • Restore the mac book air to new OS

    Hi, how can I formate and restore the macbook air to new lion OS

  • Comps.xml in Oracle 8i inventory on Windows systems

    "comps.xml" file listing the Oracle installed components along with their details is usually found in the Oracle inventory directory (%ORACLE_HOME%\Inventory\ContentsXML\comps.xml). But I noticed on a few Oracle 8i database installations that the fil