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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:41:51+00:00 2026-06-15T23:41:51+00:00

I copied the image folder from c:\book\ an put it inside the src folder,

  • 0

I copied the image folder from c:\book\ an put it inside the src folder, but picture didn’t load on Label p2.add(new JLabel(icon2));or on Button JButton j2=new JButton(icon2);. Everithing is working out accept pictures.I am a begginer , I don`t have idea what is a problem!

import javax.swing.*;
import javax.swing.ImageIcon;

import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import java.awt.*;
public class TestBorderLayout extends JFrame{

private ImageIcon icon = new ImageIcon("image/ca.gif");
private ImageIcon icon2 = new ImageIcon("image.card/1.png");
public TestBorderLayout(){


 Border lineBorder = new LineBorder(Color.BLACK, 2);    

JButton j1=new JButton("Test1");
 j1.setBackground(new Color(200,0,0));
 j1.setForeground(Color.CYAN);

 JButton j2=new JButton(icon2);

 JButton j3=new JButton("Test3");
 j3.setFont(new Font("Serif", Font.BOLD + Font.ITALIC, 12));


JPanel p1=new JPanel();
p1.setBorder(new TitledBorder("One Button"));
p1.add(j1);
p1.add(new TextField("250000000"));
JPanel p2=new JPanel();
p2.add(new JLabel(icon2));


p2.setBorder(new TitledBorder("Two Buttons"));
p2.add(j2);

p2.add(j3);

add(p1, BorderLayout.CENTER);
add(p2, BorderLayout.NORTH);


}

public static void main(String[] args){

    TestBorderLayout frame=new TestBorderLayout();
    frame.setTitle("Border");
    frame.setSize(200,300);
    frame.setLocationRelativeTo(null); // Center the frame
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

}

}
  • 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-06-15T23:41:51+00:00Added an answer on June 15, 2026 at 11:41 pm

    Instead

    new ImageIcon("image/ca.gif");
    

    do

    new ImageIcon(getClass().getResource("/image/ca.gif"));
    

    This getResource returns an URL to a resource (in jar packed file, or file on the class path), with that path. You can use relative paths, relative to the package of the class.


    Remark:

    At the end of the constructor I would do:

    setTitle("Border");
    setSize(200,300);
    setLocationRelativeTo(null); // Center the frame
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    

    That pack does the layouting. But your code is okay.

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

Sidebar

Related Questions

I am trying to copy a couple of image files from my MainBundle/SampleImages folder
I copy image files from one folder to another with help of File.Copy() method.
I'm using the below code to transfer an image from one folder on external
in which directory is an image copied when you include it in your project?
Copied from my log file ActionView::Template::Error (Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs
I copied the raw MySQL files of my website from the database directory because
I copied this class from a similar class I have in this app that
I copied this systemd service file from the lighttpd-package and adapted it to make
I am working on creating thumbnail image from the first page of pdf file.
I tried to load an image into my WPF project's main window. First I

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.