Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to create menubar and the below background color/image in java swing
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mahalakshmi
how to create menubar and the below background color/image in java swing
1 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


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


Advertisement
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();
}
}


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 a Java Runtime Editor - Swing AWT
How to create a Java Runtime Editor   Hi, I am working on a requirement in which I need to integrate a java runtime editor in swing application... using java swing, try the following code: import java.awt.BorderLayout
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 Multiple Frames using Java Swing
Multiple Frames in Java Swing In this section, you will learn how to create multiple frames. Java Swing provides the utility to show frame within another frame by providing the class JInternalFrame. With the use of this class, you can
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 Create LinkButton
Java Swing Create LinkButton You all are aware of JButtons, JRadioButtons, JToggleButtons and you have used these components in your applications. Here we are going to create a Link Button that will allow you to move to another page
Menubar and use <ul> <li> - Java Beginners
Menubar and use   I want to create a drop down menu with submenu, but have problem for one thing in IE, My button appear under the text of main menu. How can I bring it up? see the file at this address
Menubar and use <ul> <li> - Java Beginners
; background-image:url('MenuBackground.jpg... background-color:transparent...Menubar and use   I want to create a drop down menu with submenu...: uppercase; width: 18em; } #menu a { color: #000; background: url
Java Swing : JLabel Example
In this tutorial, you will learn how to create a label in java swing
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
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
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 set background of an excel sheet using POI - Java Magazine
How to set background of an excel sheet using POI  Hi, i am trying to format the excel using java. How to set the background color of an excel..., koushil Nath.  Hi friend, To set the background color of excel
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 set iText pdf document background image - Java Beginners
image for this pdf document. there is way to set the background color, but i...How to set iText pdf document background image  Hi, I have created... background color in Pdf import java.io.*; import com.lowagie.text.*; import
how to create notepad in java
how to create notepad in java  how to create notepad in java
How I can Set Transparent Background Image to Panel - Java Beginners
How I can Set Transparent Background Image to Panel  Sir ,How I can Set Transperent Background Image to Jpanel. plz Help Me
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 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 Set Transperent Background Image to Jpanel - Java Beginners
How to Set Transperent Background Image to Jpanel  Sir ,How to set Background Image to Jpanel.  Hi Friend, Try the following code...); } } ); JTextArea area=new JTextArea(15,4){ ImageIcon image = new
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 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
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
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 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
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
 

 

 

DMCA.com