Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:27:15+00:00 2026-05-26T21:27:15+00:00

I’m using a JTabbedPane, and on each tab there’s a panel, which changes when

  • 0

I’m using a JTabbedPane, and on each tab there’s a panel, which changes when the user does things like click buttons. The problem I’m getting is that elements from the previous panel get left behind. Usually you can’t see them until you run the mouse over them, but sometimes you can’t see elements of the new panel until you run your mouse over where they should be. So quite often at first only a little is visible, then:

when you run your mouse over more stuff it becomes visible

Then for some reason when you hit ‘multiple choice’, which is supposed to create the four new buttons, everything becomes perfectly visible.

I’ve got repaint(); as pretty much every other line, and before I change anything on the GUI I do removeAll(); first, but it all keeps coming back! Any suggestions? The code for this panel is below, if it might help…

package com.GC01.gui;

import java.awt.Color;

public class PracticeQuizPanel extends JPanel implements MouseListener {
    /**
     * This panel will allow the user to practice quiz questions.
     */
private static final long serialVersionUID = 1L;

private User user = new User("misha");

boolean isMultipleChoice=false;
boolean usedClue=false;
boolean isStarted=false;

Calendar calendar = Calendar.getInstance();
AnswerAnalysis aA = new AnswerAnalysis();   
private Quiz qz = new Quiz( Quiz.getQuestionsFromDisk(), 4, TabbedQuiz.getUser().getNumLogins() );

private JTextArea questionArea;
private JTextArea clueArea;
private JTextArea answerArea;

private JButton clueButton;
private JButton multiButton;
private JButton answerButton;
private JButton startButton; 

private int index=0;
private Calendar startCalendar, endCalendar;

private JPanel backPanel;

public PracticeQuizPanel(){
    add(new StartButtonPanel());
}

PracticeQuizPanel(int index) {
    createVisualElements(index);
}

public void offerAnswer(){
    endCalendar = Calendar.getInstance();
    aA.setTimeSpent((int) (endCalendar.getTimeInMillis()-startCalendar.getTimeInMillis()));
    aA.setRight(answerArea.getText());
    JOptionPane.showMessageDialog(null, aA.toString());
    answerArea.setEditable(false);
    qz.setAnswersAnalysis(index, aA);
    index++;
    removeAll(); 
    if( index<qz.getLength() ) createVisualElements(index);
    else {
        removeAll();
        JOptionPane.showMessageDialog(null, qz.toFriendlyString());
        addQuizResultsToUserProgress();
        JOptionPane.showMessageDialog(null, qz.toFriendlyString());
        UserProgress uP = new UserProgress(user);
        System.out.println(uP.toString());
    }
    repaint();
    startCalendar = Calendar.getInstance();
    //JOptionPane.showMessageDialog(null, isStarted);
}

public void addQuizResultsToUserProgress(){
    UserProgress userProgress = new UserProgress(user);
    ArrayList<AnswerAnalysis> asA = userProgress.getAnswersAnalysis();
    for (int i=0; i<qz.getLength(); i++){
        asA.add( qz.getAnswersAnalysis()[i]);
    }
    userProgress.setAnswersAnalysis(asA);
    userProgress.saveProgress();
}



/**
 * This method creates/recreates all the text boxes, buttons etc. without resetting the quiz and
 * the objects in memory.
 */
private void createVisualElements(int index){
    if (TabbedQuiz.getUser().getNumLogins()<0) 
        JOptionPane.showMessageDialog(null, "There was an error. You may have done this quiz before.");
    removeAll();
    repaint();
    startCalendar = Calendar.getInstance();
    this.index=index;
    setBackground(new Color(112, 128, 144)); 
    setBounds(0,0,728,380);
    setLayout(null);

    questionArea = new JTextArea();
    questionArea.setFont(TabbedQuiz.getDefaultFont().deriveFont(20));//new Font("Courier New", 0, 20));
    questionArea.setEditable(false);
    questionArea.setLineWrap(true);
    questionArea.setWrapStyleWord(true);
    questionArea.setBounds(295, 11, 423, 74);
    add(questionArea);
    //int index=0;
    Question q = qz.getQuestions().get(index);
    aA = new AnswerAnalysis(q.getQuestionID());
    questionArea.setText(q.getQuestionText() );

    clueArea = new JTextArea();
    clueArea.setFont(TabbedQuiz.getDefaultFont().deriveFont(20));
    clueArea.setEditable(false);
    clueArea.setLineWrap(true);
    clueArea.setWrapStyleWord(true);
    clueArea.setBounds(295, 104, 423, 55);
    add(clueArea);

    JLabel lblQuestion = new JLabel("QUESTION:");
    lblQuestion.setFont(TabbedQuiz.getDefaultFont().deriveFont(40));
    lblQuestion.setBounds(43, 11, 216, 61);
    add(lblQuestion);

    answerArea = new JTextArea();//index+"");
    answerArea.setFont(TabbedQuiz.getDefaultFont().deriveFont(20));
    answerArea.setLineWrap(true);
    answerArea.setWrapStyleWord(true);
    answerArea.setBounds(295, 301, 423, 50);
    answerArea.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if(e.getKeyCode() == KeyEvent.VK_ENTER) offerAnswer();
        }
    });

    add(answerArea);
    answerArea.setFocusable(true);
    answerArea.requestFocusInWindow();

    clueButton = new JButton("CLUE?");
    clueButton.setFont(TabbedQuiz.getDefaultFont().deriveFont(40));
    clueButton.addMouseListener(this);
    clueButton.setBounds(15, 104, 244, 55);
    add(clueButton);

    multiButton = new JButton("MULTIPLE CHOICE?");
    multiButton.setFont(TabbedQuiz.getDefaultFont().deriveFont(20));
    multiButton.addMouseListener(this);
    multiButton.setBounds(15, 195, 244, 55);
    add(multiButton);

    answerButton = new JButton("ANSWER!");
    answerButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        }
    });
    answerButton.setFont(TabbedQuiz.getDefaultFont().deriveFont(40));
    answerButton.setBounds(15, 301, 244, 55);
    answerButton.addMouseListener(this);
    add(answerButton);

    backPanel = new JPanel();
    backPanel.setBounds(0, 0, 728, 380);
    //add(backPanel);

    this.setVisible(true);
    repaint();
}

@Override
public void mouseClicked(MouseEvent e) {
    if      ( e.getSource().equals(startButton)  ) {
        remove(startButton); repaint(); isStarted=true;
        startCalendar = Calendar.getInstance();
    }
    else if ( e.getSource().equals(answerButton) ) offerAnswer();
    else if ( e.getSource().equals(clueButton )  ) {
        clueArea.setText(clueArea.getText() + qz.getQuestions().get(index).getClueText() + "\n");
        aA.setUsedClue(true);
        //JOptionPane.showMessageDialog(null, "hi");
        }
    else if ( e.getSource().equals(multiButton)  ) {            
        String[] answerOptions = qz.getQuestions().get(index).getAnswerOptions(3);
        JButton[] optionsButtons = new JButton[4];
        for(int j=0;j<4;j++){
            optionsButtons[j]=new JButton(answerOptions[j]);
            if(optionsButtons[j].getText().length()>13) 
                optionsButtons[j].setFont(TabbedQuiz.getDefaultFont().deriveFont(10));
            else optionsButtons[j].setFont(TabbedQuiz.getDefaultFont().deriveFont(15));
            if(j<2) optionsButtons[j].setBounds(295+211*j       , 170, 211, 55);
            else    optionsButtons[j].setBounds(295+211*(j-2)   , 226, 211, 55);
            optionsButtons[j].addMouseListener(this);
            optionsButtons[j].setName("optionsButton"+"["+j+"]");
            add(optionsButtons[j]);
            repaint();
        }
        aA.setMultipleChoice(true);
    }
    else if ( ( (JButton) e.getSource() ).getName().startsWith("optionsButton") ) {
        String answerOffered = ( (JButton) e.getSource() ).getText();
        answerArea.setText(answerOffered);
        offerAnswer();
    }
}

@Override
public void mouseEntered(MouseEvent e) {
    if(e.getSource()!=startButton && e.getSource().getClass().equals( answerButton.getClass()) ){
        ( (JButton) e.getSource() ).setBackground(Color.green);
    }if(index>0 && e.getSource()==startButton) remove(startButton);
}

@Override
public void mouseExited(MouseEvent e) {
    if(e.getSource()!=startButton && e.getSource().getClass().equals( answerButton.getClass()) ){
        ( (JButton) e.getSource() ).setBackground(UIManager.getColor("control"));
    }
}

@Override
public void mousePressed(MouseEvent e) {
}

@Override
public void mouseReleased(MouseEvent e) {
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:27:16+00:00Added an answer on May 26, 2026 at 9:27 pm

    To anyone else with this issue: I eventually solved the problem. setVisible(false); setVisible(true);. Put it EVERYWHERE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.