how to create menubar and the below background color/image in java swing

how to create menubar and the below background color/image in java swing

how to create menubar and the below background color/image in java swing

View Answers

April 1, 2011 at 5:33 PM

import java.io.*;
import java.awt.*;
import javax.swing.*;
import javax.imageio.*;
import java.awt.image.*;
import java.awt.event.*;

public class MenuBarExample_BackgroundImage  implements ActionListener{
private  static BufferedImage image;
private  static JPanel  panel = new JPanel(){
protected void paintComponent(Graphics g){
super.paintComponent(g);
if(image != null){
g.drawImage(image, 0, 0, this);
}
}
};
MenuBarExample_BackgroundImage(){
panel.setLayout(null);
JMenuBar menubar = new JMenuBar();
    JMenu menu = new JMenu("Select");
    JMenuItem Item1 = new JMenuItem("c:\\flower1.jpg");
    JMenuItem Item2 = new JMenuItem("c:\\flower2.jpg");
    JMenuItem Item3 = new JMenuItem("c:\\flower3.jpg");
    JMenuItem Item4 = new JMenuItem("c:\\flower4.jpg");
    menu.add(Item1);
    menu.add(Item2);
    menu.add(Item3);
    menu.add(Item4);
    menubar.add(menu);
    Item1.addActionListener(this);
    Item2.addActionListener(this);
    Item3.addActionListener(this);
    Item4.addActionListener(this);
    JFrame f=new JFrame();
    f.setJMenuBar(menubar);
    f.add(MenuBarExample_BackgroundImage.getPanel());
    f.setSize(300,200);
    f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
            String st=e.getActionCommand();
            try{
File file=new File(st);
image = ImageIO.read(file);
Dimension imageSize = new Dimension(image.getWidth(), image.getHeight());
panel.setPreferredSize(imageSize);
panel.repaint();     
}

catch(Exception ex){}
        }
public  static JPanel getPanel(){
return panel;
}

public static void main(String[] args){
new MenuBarExample_BackgroundImage();
}
}

Ads









Related Tutorials/Questions & Answers:
how to create menubar and the below background color/image in java swing
how to create menubar and the below background color/image in java swing  how to create menubar and the below background color/image in java swing
how to create reports in swing java?
how to create reports in swing java?  how to create reports in swing java
Advertisements
how to create a header in jtable using java swing
how to create a header in jtable using java swing  how to create a header in jtable using java swing   d
java how to create visual swing editor
java how to create visual swing editor   How do I create a visual swing designer in java ?Meaning that I can "draw" a button,a JTextArea from within my designer program . I just need some basics . I've got no idea how to start
How to create Runtime time jLabel in java swing ?
How to create Runtime time jLabel in java swing ?   hi sir. my problem is that i want to display database row on a jLabel. Suppose i retrived... will itself enter the number of Jlabel that will create on Panel. if user enter-3, ther
Swing In Java
. This example will demonstrate you about how to use the Swing components in Java...Swing In Java In this tutorial we will read about the various aspects of Swing... technologies. Later, the JFC was renamed to Swing. Before, the Java version 1.2
How to create Notepad in Swing
How to create Notepad in Swing Program Description:- In this Example we have... is the main container for swing-based application. This example we have created... final long serialVersionUID = 1L; JFrame frame; JMenuBar menuBar; JMenu file
Java Swing : JLabel Example
In this tutorial, you will learn how to create a label in java swing
Storing the Color Image pixel values into 2d array
Storing the Color Image pixel values into 2d array  i want to store the color image pixel values into 2d array and agiain the array have to store into a text file using java... plz provide the code
How to draw in jPanel? swing/graphics Java
How to draw in jPanel? swing/graphics Java  How to draw in jPanel? (swing/graphics Java
create, edit ,open simple documents using java - Swing AWT
want to use Java Swing or JSP? Do you want to create word document file...create, edit ,open simple documents using java   In my program I have a text area.How to create document which will contain text in text
How to set the Gradient Color as a background color for Java Frame?
How to set the Gradient Color as a background color for Java Frame?  How to set the Gradient Color as a background color for Java Frame
JSlider Component of Java Swing
JSlider Component of Java Swing       In this section, you will learn how to create a JSlider component of Java Swing. A Slider is a Swing tool which you can use for selecting
How to change background, change background
How to change background       This example will teach you to change background of any object... a picture to change background. Selection: Make selection by the Magic wand tool
How to design a background, design a background, a background
How to design a background     ... how to design a background by this example. New File: Take a new file. Choose color: First set the foreground and background color. Clouds: Go to Filter menu
Creating Check Box in Java Swing
Creating Check Box in Java Swing       This section illustrates you how to create a Check Box component in Java Swing. In this section, you can learn simply creating the Check Box
Creating a JTabbedPane Container in Java Swing
to create the JTabbedPane container in Java Swing. The example for illustration... Creating a JTabbedPane Container in Java Swing  ... of swing to implement the JTabbed component of Java. The following figure shows
Java Swing : JFrame Example
Java Swing : JFrame Example In this section, you will learn how to create a frame in java swing. JFrame : JFrame class is defined in javax.swing.JFrame.... to create frame by using JFrame swingCreate object of JFrame
How to Hide Button using Java Swing
Programming application how to hide the buttons using Java Swing. Please Visit this below reference link http://www.roseindia.net/tutorial/java/swing...How to Hide Button using Java Swing  Hi, I just begin to learn java
java swing in netbeans
java swing in netbeans  how can create sub menu in java swing using..."); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); JMenu... backwardMenuItem = new JMenuItem("Java"); newmenu.add(backwardMenuItem
which values we have to use for compressing any color image
which values we have to use for compressing any color image  Sir........... in the process of compressing of any color image, which values do use as input for comprseeing algorithm. and how to get the image matrix from color
Java Swing dependent JList
Java Swing dependent JList In this section, you will learn how to create a dependent list using java swing In the given code, we have created three lists. In the first list we have displayed the  names of the databases present
how to set background image
how to set background image  how to set image in background in that image i want over lay text how it possible in jsp? using flash image how it is overlayed in jsp page? thanks
how to create notepad in java
how to create notepad in java  how to create notepad in java
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
How to create charts in Java?
How to create charts in Java?  Is there any example of creating charts and graphs in Java? thanks   Hi, check the tutorial: Chart & Graphs Tutorials in Java Thanks
Get the color values as a matrix of color image
Get the color values as a matrix of color image  I am new to java and image processing, i want to get the color values as a matrix from the color image for giving input to the compression algorithm by using java. plz provide
How to Create Keyboard in JAVA
How to Create Keyboard in JAVA  please help me to create On-Screen Keyboard with java and please give me an another idia to make it ..............iam waiting for your help ,think u so much
Chess Application In Java Swing
.style1 { margin-right: 0px; } Chess Application In Java Swing       In this section, you will learn how to create chess game in java swing
steps to create desktop application in java swing using eclipse with drag and drop options
steps to create desktop application in java swing using eclipse with drag and drop options  please help to create desktop application in java swing using eclipse with drag and drop and what are the plugins required
How to create form in Swings
How to create form in Swings  How to create registration, login and question form in Java Swing?   Creating different forms in Java Swing - Examples how to create registration form in swing swing login form example

Ads