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 7623991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:50:47+00:00 2026-05-31T04:50:47+00:00

When I run my code it doesn’t show up. Basically I have a custom

  • 0

When I run my code it doesn’t show up.
Basically I have a custom Jcomponent which I add to my JFrame or View and then create a View that makes the frame in my main method.
I already added to JFrame here is my code for the JComponent:

public class CardDisplay extends JComponent {
private Card card;
private Image cardImage;

public CardDisplay()
{
    cardImage = Toolkit.getDefaultToolkit().createImage(("Phase10//res//Blue2.png"));
}

@Override
public void paint(Graphics g)
{
    g.drawImage(cardImage, 125 ,200, this);
}
public class View {
public View(){

}

public void makeFrame()
{
   JFrame frame = new JFrame("Phase 10");
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setLayout(new BorderLayout());
   JPanel handPanel = new JPanel();
   CardDisplay cd = new CardDisplay();
   handPanel.setLayout(new FlowLayout());
   frame.add(handPanel, BorderLayout.SOUTH);
   handPanel.add(cd);
   frame.pack();
   frame.setSize(600,500);
   frame.setResizable(false);
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
}

public static void main(String[] args){
    View view = new View();
    Game game = new Game();
    view.makeFrame();
    //game.run();

}
  • 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-31T04:50:49+00:00Added an answer on May 31, 2026 at 4:50 am

    Here is the working version. The problem was mainly related to the preferred size of the component. Please note the implementation of method getPreferredSize().

    If you would like to see what are the component boundaries I’d recommend using MigLayout layout manager in debug mode (the site has all necessary documentation).

    public class CardDisplay extends JComponent {
        private BufferedImage cardImage;
    
        public CardDisplay() {
            try {
                cardImage = ImageIO.read(new File("Phase10//res//Blue2.png"));
            } catch (final IOException e) {
                e.printStackTrace();
            }    
        }
    
        @Override
        public void paintComponent(final Graphics g) {
            super.paintComponent(g);
            g.drawImage(cardImage, 0, 0, null);
        }
    
        @Override
        public Dimension getPreferredSize() {
            if (cardImage == null) {
                return new Dimension(100, 100);
            } else {
                return new Dimension(cardImage.getWidth(null), cardImage.getHeight(null));
            }
        }
    
        public static class View {
            public View() {}
    
            public void makeFrame() {
                final JFrame frame = new JFrame("Phase 10");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                final JPanel handPanel = new JPanel();
                final CardDisplay cd = new CardDisplay();
                handPanel.setLayout(new FlowLayout());
                frame.add(handPanel, BorderLayout.SOUTH);
                handPanel.add(cd);
                frame.pack();
                frame.setResizable(false);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        }
    
        public static void main(final String[] args) {
            final View view = new View();
            view.makeFrame();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sample code which doesn't seem to want to run. import
I mean, how does Java decide which protocols are available? I run some code
Does anybody have a short code sample that can be run in the VS
i need run code that will create a database and populate tables. i am
The following code doesn't appear to run when executed by code: Stored procedure snippet:
I have setup Sonar and want to run the code analysis as part of
I seem to have run into a peculiar problem. Here is the code #read
I commonly run into the following situation where I have a data structure which
As you know php code doesn't compile to run,they are only script. but I
I have some code that I want to run in a utility application whenever

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.