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









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
to create the User Interfaces components. But, since Java 1.2 Swing... will demonstrate you about how to use the Swing components in Java applications...Swing In Java In this tutorial we will read about the various aspects of Swing
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... { private static final long serialVersionUID = 1L; JFrame frame; JMenuBar menuBar
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
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
Java Swing : JLabel Example
In this tutorial, you will learn how to create a label in java swing
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
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.ADS_TO_REPLACE_1 Choose color: First set the foreground and background color. Clouds
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 change background, change background
How to change background       This example will teach you to change background of any object... of the another picture to make background picture. Paste: Go to Edit menu > Paste
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
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
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
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 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
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
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
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....); } } Description : The above example shows how to create frame by using
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 MS WORD like document file using Java Swing - Swing AWT
create , edit MS WORD like document file using Java Swing   In my... document file. Then how should I create, edit , retrieve this document file? I am using Java SWING. Plz. email your answer
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 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
SplitPane in Java Swing
Learn SplitPane in Java Swing In this section, you will learn how to create split pane using java swing. For this, we have used JSplitPane class... is the code Splitpane in Java Swing: import java.awt.*; import 
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
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
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
background
background  how to add image as background to a frame
Create a JRadioButton Component in Java
Create a JRadioButton Component in Java       In this section, you will learn how to create a radio button in java swing. Radio Button is like check box. Differences between check
Create a Scroll Pane Container in Java
to create a scroll pane container in Java Swing. When you simply create a Text Area... Create a Scroll Pane Container in Java   ... adding the JScrollPane component of Java Swing. Following is the screen shot
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 notepad in java
how to create notepad in java  how to create notepad in java
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 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
Create Round Button in Java swing
Create Round Button in Java swing In this tutorial, we are going to create a button of round shape. Java2D APIs and Java Swing make it easy to implement... have overridden the method paintComponent() to give color to the background
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
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
java swing - Swing AWT
java swing  how i can insert multiple cive me exampleolumn and row in one JList in swing?plz g  Hi Friend, Please clarify your question. Thanks
Java Swing Create XML file
Java Swing Create XML file In this tutorial, you will learn how to create XML... swing components and display it in xml file. We have created textfields... and fetch all the data from textfields and create an xml file with proper
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
How to make a chrome background, make a chrome background, chrome background
How to make a chrome background     ... background so follow all the steps as given in this example. New Document: First take a new document with any color background and fill "White" color

Ads