Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java.swing.image

import javax.swing.ImageIcon; //導入方法依賴的package包/類
private void setIconButtons()

    {
        homeIcon = new ImageIcon("icon/home.png");
        Image icon = homeIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH);
        homeIcon.setImage(icon);
        home.setIcon(homeIcon);
        
        nextIcon = new ImageIcon("icon/next.png");
        icon = nextIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH);
        nextIcon.setImage(icon);
        next.setIcon(nextIcon);
        
        backIcon = new ImageIcon("icon/back.png");
        icon = backIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH);
        backIcon.setImage(icon);
        back.setIcon(backIcon);
        
        /*endIcon = new ImageIcon("icon/end.png");
        icon = endIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH);
        endIcon.setImage(icon);
        end.setIcon(endIcon);*/
    }
Comment

java swing pic

BufferedImage myPicture = ImageIO.read(new File("path-to-file"));
JLabel picLabel = new JLabel(new ImageIcon(myPicture));
add(picLabel);
Comment

java swing pic


import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ImagePanel extends JPanel{

    private BufferedImage image;

    public ImagePanel() {
       try {                
          image = ImageIO.read(new File("image name and path"));
       } catch (IOException ex) {
            // handle exception...
       }
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image, 0, 0, this); // see javadoc for more info on the parameters            
    }

}

Comment

PREVIOUS NEXT
Code Example
Java :: system.out.print two dimensional array 
Java :: java parallel sort 
Java :: create method setsupportactionbar 
Java :: Read from text file android studio 
Java :: java scanner input float 
Java :: java create new thread 
Java :: {} when initialising arraylist java 
Java :: replace all punctuation in string java 
Java :: java transfer file over socket 
Java :: java find time between two dates 
Java :: expected exception junit 
Java :: java try catch 
Java :: how to do stuff with a scoreboard minecraft 
Java :: how to convert bitmap to uri in android 
Java :: How to perform a breadth first search through a binary tree, in Java? 
Java :: spinner event in android 
Java :: android recyclerview show hide item with animation with default animation 
Java :: how to enable cors request on springboot application 
Java :: intent filter 
Java :: concatenate two arrays java 
Java :: byte array to base64 string 
Java :: in place transpose in a matrix in java 
Java :: counting nodes in binary search tree 
Java :: java replace all not number 
Java :: split string into int array 
Java :: bytes to string solidity 
Java :: localdate java 
Java :: retrofit implementation 
Java :: java % 
Java :: print float number with only four places after the decimal point in java 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =