English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i have created a frame. On the top portion of the frame i want to display an image of jpeg format and the bottom part should contain 3 buttons, can some one let me know how to do this !

2007-03-21 09:09:09 · 2 answers · asked by chintu_victor 1 in Computers & Internet Programming & Design

2 answers

Here's a simple example that you can pass in the file path to the image file as a String to the constructor. It uses the ImageIcon implementation of the Icon interface to render a jpeg, gif, or png image onto a JLabel for display. Note: most Swing components have a setIcon(Icon icon) method, including JButton.

import javax.swing.*;
import java.awt.*;

public class PictureFrame extends JFrame{

private JButton one = new JButton("One");
private JButton two = new JButton("Two");
private JButton three = new JButton("Three");

public PictureFrame(String imagePath){
JPanel imagePanel = getImagePanel(imagePath);
getContentPane().add(imagePanel, BorderLayout.NORTH);
JPanel buttonPanel = getButtonPanel();
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
}

private JPanel getImagePanel(String imagePath){
Icon icon = new ImageIcon(imagePath);
JLabel imageLabel = new JLabel(icon);
JPanel panel = new JPanel(new BorderLayout());
panel.add(imageLabel);
return panel;
}

private JPanel getButtonPanel(){
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
panel.add(one);
panel.add(two);
panel.add(three);
return panel;
}

/** Test by passing in file path to image file.*/
public static void main(String[] args){
JFrame f = new PictureFrame(args[0]);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}

}

2007-03-22 16:59:35 · answer #1 · answered by vincentgl 5 · 0 0

Open the be conscious checklist. pick the image, suitable-click, replica. Open Paint. In Paint, click Edit, Paste then, report, shop AS situation a filename that is going to shop as a bitmap in case you like

2016-10-19 06:52:50 · answer #2 · answered by juart 4 · 0 0

fedest.com, questions and answers