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

Ads
 

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
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
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 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
How to draw in jPanel? swing/graphics Java
How to draw in jPanel? swing/graphics Java  How to draw in jPanel? (swing/graphics Java
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 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 create interfaces in java
how to create interfaces in java  HI, Here is my code public interface validateInfo { public void validate(String empcode, String password); } class updateInfo implements validateInfo { public void update() { //code
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
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 create first program in Java?
How to create first program in Java?  Hi, I am new in Java programming. Tell me How to create first program in Java? Thanks   Hi, Read more at First Java Program. Thanks
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
How to create and use Array in Java?
How to create and use Array in Java?  Hi, How to create and use Array in Java? Write program to construct and use the array. Thanks   Hi... can read complete example at Array in Java. Thanks
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
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
How to create first Java Program?
How to create first Java Program?  Hi, I am beginner and I want to write first Java program. How I can setup my machine and write first Java program... and run first Java program: Create program in Note pad: Step 1: Open
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 users in LDAP using java?
how to create users in LDAP using java?  how to create users in LDAP using java
how create package of this java code
how create package of this java code  Hi,i have email code in java which is working fine with out making package but when i want to make package of this code its stop working.Its showing exception while I execute it.I have to use
how create package of this java code
how create package of this java code  Hi,i have email code in java which is working fine with out making package but when i want to make package of this code its stop working.Its showing exception while I execute it.I have to use
how to create forum on java subject in jsp/servlet ?
how to create forum on java subject in jsp/servlet ?  hi , i want to implement forum on java subject in jsp/servlet technology .how can i do it,which is the table required for it in mysql? formate like what is java is ? 2Reply
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java

Ads