Placing buttons on top of a rectangle..
I have 5 button that i placed on my applet by specifying its exact location
by using setBounds...for example, i have...
btnOne.setBounds(15,159,120,40)...etc.
I want to place these five buttons on top of a black rectangle, so that the
black rectangle is serves as a background. How can I do this in Java? I also,
wanted to place text over an image i have in my applet but am experience
problems.
thanx
trin
You can put the buttons in a panel and set the background color of the panel to black. Then you just have to add the panel to your applet.
Similar Messages
-
Problem placing buttons on top of a background image
My knowledge of Java isn't the greatest and I am currently having problems placing buttons on top of a background image within a JApplet (this is also my first encounter with Applets).
I'm using a Card Layout in order to display a series of different screens upon request.
The first card is used as a Splash Screen which is displayed for 5 seconds before changing to the Main Menu card.
When the Main Menu card is called the background image is not shown but the button is.
While the Applet is running no errors are shown in the console.
Full source code can be seen below;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
// First extend JApplet
public class WOT extends JApplet {
//--------------- Variables are declared here -----------------
private CardLayout contentCardLayout = new CardLayout(); // declare CardLayout
private Container contentContain; // declare content Container
private JPanel contentCard, splashScreen, mainMenu, menuImage; // declare content Panels
private JLabel splash, menu, map; // declare image labels
private ImageIcon mapBtn; // declare ImageIcons
private JButton mapOption; // declare option Buttons
private Timer timer; // declare Timer
private ActionListener actionListener, mapOptionListener; // declare ActionListener
//--------------- Initialise Applet -----------------
public void init() {
//--------------- Set-up Card Layout -----------------
contentCard = new JPanel(contentCardLayout); // assign card panels to CardLayout
//--------------- Splash Screen -----------------
splashScreen = new JPanel();
splash = new JLabel(new ImageIcon(getClass().getResource("img/bg.gif")));
splashScreen.add(splash);
splashScreen.setSize(600,800);
splashScreen.setLocation(0,0);
//--------------- "View Map" Option Button -----------------
mapBtn = new ImageIcon(getClass().getResource("img/map.gif"));
mapOption = new JButton(mapBtn);
mapOption.setBorder(null);
mapOption.setContentAreaFilled(false);
mapOption.setSize(150,66);
mapOption.setLocation(150,450);
mapOption.setOpaque(false);
mapOption.setVisible(true);
//--------------- Main Menu Screen -----------------
//menuImage = new JPanel(null);
//menuImage.add(mainMenu);
//menuImage.setLocation(0,0);
mainMenu = new JPanel(null);
menu = new JLabel(new ImageIcon(getClass().getResource("img/menu.gif")));
menu.setLocation(0,0);
mainMenu.add(menu);
//mainMenu.setBackground(Color.WHITE);
mainMenu.setLocation(0,0);
mainMenu.setOpaque(false);
//mainMenu.setSize(150,66);
mainMenu.add(mapOption);
//--------------- Map Image Screen -----------------
map = new JLabel(new ImageIcon(getClass().getResource("img/map.gif")));
//--------------- Add Cards to CardLayout Panel -----------------
contentCard.add(splashScreen, "Splash Screen");
contentCard.add(mainMenu, "Main Menu");
contentCard.add(map, "Map Image");
//--------------- Set-up container -----------------
contentContain = getContentPane(); // set container as content pane
contentContain.setBackground(Color.WHITE); // set container background colour
contentContain.setLocation(0,0);
contentContain.setSize(600,800);
contentContain.setLayout(new FlowLayout()); // set container layout
contentContain.add(contentCard); // cards added
//--------------- Timer Action Listener -----------------
actionListener = new ActionListener()
public void actionPerformed(ActionEvent actionEvent)
//--------------- Show Main Menu Card -----------------
contentCardLayout.show(contentCard, "Main Menu");
//--------------- Map Option Button Action Listener -----------------
mapOptionListener = new ActionListener()
public void actionPerformed(ActionEvent actionEvent)
//--------------- Show Main Menu Card -----------------
contentCardLayout.show(contentCard, "Map Image");
//--------------- Timer -----------------
timer = new Timer(5000, actionListener);
timer.start();
timer.setRepeats(false);
}Any help would be much appreciated!
Edited by: bex1984 on May 18, 2008 6:31 AM1) When posting here, please use fewer comments. The comments that you have don't help folks who know Java read and understand your program and in fact hinder this ability, which makes it less likely that someone will in fact read your code and help you -- something you definitely don't want to have happen! Instead, strive to make your variable and method names as logical and self-commenting as possible, and use comments judiciously and a bit more sparingly.
2) Try to use more methods and even classes to "divide and conquer".
3) To create a panel with a background image that can hold buttons and such, you should create an object that overrides JPanel and has a paintComponent override method within it that draws your image using the graphics object's drawImage(...) method
For instance:
an image jpanel:
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;
public class BackgroundImage
// **** this will have to be changed for your program:
private static final String IMAGE_PATH = "../../m02/a/images/Forest.jpg";
private BufferedImage myImage = null;
private JPanel imagePanel = new JPanel()
@Override
protected void paintComponent(Graphics g)
{ // *** here is where I draw my image
super.paintComponent(g); // **** don't forget this!
if (myImage != null)
g.drawImage(myImage, 0, 0, this);
public BackgroundImage()
imagePanel.setPreferredSize(new Dimension(600, 450));
imagePanel.add(new JButton("Foobars Rule!"));
try
myImage = createImage(IMAGE_PATH);
catch (IOException e)
e.printStackTrace();
catch (URISyntaxException e)
e.printStackTrace();
private BufferedImage createImage(String path) throws IOException,
URISyntaxException
URL imageURL = getClass().getResource(path);
if (imageURL != null)
return ImageIO.read(new File(imageURL.toURI()));
else
return null;
public JPanel getImagePanel()
return imagePanel;
}and an applet that uses it:
import java.lang.reflect.InvocationTargetException;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
public class BackgrndImageApplet extends JApplet
@Override
public void init()
try
SwingUtilities.invokeAndWait(new Runnable()
@Override
public void run()
getContentPane().add(new BackgroundImage().getImagePanel());
catch (InterruptedException e)
e.printStackTrace();
catch (InvocationTargetException e)
e.printStackTrace();
} -
i am building an menu in DVDSP, and im creating drop zones, but i want the outside to be highlighted around it. as in, i want the outer edge ring of the video to change colors as selected. so i created the button, and created the drop zone in front of it. when i go to the simulator, the button is on top, completely covering my drop zone video. is there any way to change this?
ive already tried bringing it forward. when i make the drop zone bigger, i can see it outside of the button.For example: I have a movie placed in my article. And on top of the movie I want to place a button. The "mask/dummy overlay" function isn't working because the button will lose his function. Is there an other way to place a button on top of an interactive element?
Tal -
Button on Top of VF0050 webcam
Can someone tell me what the button on the top of the webcam is for/
For example: I have a movie placed in my article. And on top of the movie I want to place a button. The "mask/dummy overlay" function isn't working because the button will lose his function. Is there an other way to place a button on top of an interactive element?
Tal -
How can i place button on top right hand corner of the tabbed pane
Hi all,
i want to place button on top right hand corner of the tabbed pane, just run the code below, i have add button(it going to insert tab into tabbedpane), i want to place that tab into top right hand corner of the tabbedpane (not inside the tab itself). if i set tab policy setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT), it will give two button at right hand corner along with those buttons i want to and one more add button.
please suggest so that i can move forward.
Thanks in advance
import java.awt.Dimension;
import java.util.HashMap;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
* @author Dayananda.BV
public class TabpaneDemo extends javax.swing.JFrame {
/** Creates new form TabpaneDemo */
HashMap<Integer, tabpanel> panelMap = new HashMap<Integer, tabpanel>();
public TabpaneDemo() {
initComponents();
createFloorPlan();
getContentPane().setPreferredSize(new Dimension(400,400));
jTabbedPane1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
add_tab_button = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
add_tab_button.setText("+");
add_tab_button.setMargin(new java.awt.Insets(0, 0, 0, 0));
add_tab_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
add_tab_buttonActionPerformed(evt);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(308, Short.MAX_VALUE)
.addComponent(add_tab_button, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(67, 67, 67))
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(add_tab_button)
.addGap(8, 8, 8)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))
pack();
}// </editor-fold>
private void createFloorPlan(){
tabpanel floorplan_Panel = new tabpanel(panelMap.size()+1);
panelMap.put(floorplan_Panel.getTabIndex(), floorplan_Panel);
jTabbedPane1.add(floorplan_Panel, floorplan_Panel.getTabName());
jTabbedPane1.setSelectedIndex(jTabbedPane1.getTabCount()-1);
private void add_tab_buttonActionPerformed(java.awt.event.ActionEvent evt) {
createFloorPlan();
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TabpaneDemo().setVisible(true);
// Variables declaration - do not modify
private javax.swing.JButton add_tab_button;
private javax.swing.JTabbedPane jTabbedPane1;
// End of variables declaration
class tabpanel extends JPanel{
private int tabIndex = 0;
private String tabName ;
public tabpanel(int tabIndex) {
this.tabIndex = tabIndex;
if(tabIndex >= 10) {
tabName = "Floor Map"+tabIndex;
} else{
tabName = "Floor Map"+tabIndex+" ";
public int getTabIndex(){
return tabIndex;
public String getTabName(){
return tabName;
}Thanks
Dayananda B VThis part of tabbed pane is not customizable as it lies in the ComponentUI(TabbedpaneUI) portion of the tabbedpane.
But I can point out the place u can change to bring the desired feature into effect.
U can find an Inner class called ScrollableTabSupport
Look for the methods createButtons where u can create extra buttons and add to the tabbed pane.
The Inner class also implements actionListener where u can implement the action for the button u added.
By this method U have to use your own extended TabbedPaneUI which u cant escape from.
Hope this will help u. -
Hi I have an iPhone 4 and suddenly it stopped working. Could here notifications and nothing on the diisplay. Wake up button on top is not working. so unable to restart the phone. Wanted to try restore from iTunes but Find my iPhone (iCloud) is on. How to recover or restart my Phone
Follow these steps to log into your iCloud account on your computer and deactivate "Find my iPhone" on your device:
Remove an iOS device or Mac on which you can’t turn off Find My iPhone
If you can’t turn off Find My iPhone on the device, turn off the device so it goes offline, then remove it from Find My iPhone on iCloud.com.
Note: You can also remove your iOS device by first erasing it—just follow the instructions below for removing an iOS device you don’t have. You can later restore the device from an iCloud or iTunes backup.
Turn off the device you want to remove.
Sign in to icloud.com/#find on another computer with your Apple ID (the one you use with iCloud). If you’re using another iCloud app, click the app’s name at the top of the iCloud.com window, then click Find My iPhone.
Click All Devices, select the offline device, then click Remove from Account. If you don’t see Remove from Account, click All Devices again, then click the Delete button next to the device. If the device comes online again, it will reappear in Find My iPhone. If your device reappears, turn off Find My iPhone on the device (follow the instructions above for removing a device by turning off Find My iPhone), or if it’s an iOS device and you no longer have it, follow the instructions below for removing an iOS device you no longer have.
Remove an iOS device you no longer have
If you no longer have the iOS device because you gave it away or sold it, you need to remotely erase it before you can remove it.
Sign in to icloud.com/#find with your Apple ID (the one you use with iCloud). If you’re using another iCloud app, click the app’s name at the top of the iCloud.com window, then click Find My iPhone.
Click All Devices, then select the device.
Click Erase [device], then enter your Apple ID password. Because the device isn’t lost, don’t enter a phone number or message.
Note: If you’re trying to erase a family member’s device, that person will need to enter his or her Apple ID password on this device. If the device is offline, the remote erase begins the next time it’s online. You’ll receive an email when the device is erased.
When the device is erased, click Remove from Account.All your content is erased, and someone else can now activate the device.
copied from: iCloud: Remove your device from Find My iPhone -
I tried changing my password, and it changed to one that wasnt it, and i dont know it. So i tried it too many times and now its saying it is disabled, connect to itunes. but a problem is that my power button on top is broken. how to i fix it?
Disabled
Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
iOS: Wrong passcode results in red disabled screen
If recovery mode does not work try DFU mode.
How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
For how to restore:
iTunes: Restoring iOS software
To restore from backup see:
iOS: How to back up
If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
You can redownload most iTunes purchases by:
Downloading past purchases from the App Store, iBookstore, and iTunes Store -
my ipod screen has went white i have tried plugging it into itunes and pressing the home button and top button together for 10 seconds but it wont work!! this has happened twice before already and i havent even had it a year yet, i should have listened to my sister and never have bought one!!! someone help please ?
- Connect to computer and it it shows in iTune restore via iTunes
- Then try letting the battery fully drain. After charging for an hour try the reset (both buttons) and connecting to computer and restore. -
Pdf converter button on top of the browser disappeared.
I have adobe acrobat 9. I had a Pdf converter button on top og the browser that I used to convert web pages to pdf documents. This button disappeared last week. Could it be restored? I tried reinstalling the software and tried internet options to make sure third party extensions were checked.
Sorry, moving doesn't seem to be working right now, but you should post your question here:
http://forums.adobe.com/community/acrobat
This forum is for photoshop elements, the consumer version of photoshop. -
i have been using firefox 3.6.16 and just upgraded to version 4 last night. actually the problem is this, in my browser the 'firefox button' and all tabes are shown in the same lane on top.
what i want is to get the default look of firefox 4 with firefox button on top and all the tabs appearing on beneath this button..(not in same lane)
am i having due to any preference setting or else? please helpIf the Firefox window is maximized, it will display the tabs in the same line as the Firefox button, it only displays them on a separate line on a non-maximized window.
-
Please help me!!! The lock button on top of my Iphone 4 is pushed down completely and is stuck! And then yesterday I looked down and my iphone was completely black. It would not turn on seeing as how I could not push the top button to reset it to turn back on and then also it would not respond to a charge. I was wondering if anyone could suggest anything at all in how to turn it back on and bring it back to life and if there was any way I could save my photos and such off there! Thank you!!
SIDE NOTE!!!!!!!!!
This phone does NOT have water damage and was working just fine until i had this problem -
On my iPad2, the buttons for Top Ten, Genres and New Releases are missing. How do I get them back.
If the menu bar is hidden then press the F10 key or hold down the Alt key, that should make the menu bar appear.
* Go to "View > Toolbars" and check-mark "Menu Bar" with a click if you want to make that permanent
See [[Menu bar is missing]] -
Close, minimize, resize buttons in top left dissapeared
Any help MUCH appreciated!!... I cannot seem to figure out how i've lost my close, minimize and resize buttons in top left. IT's only in Illustrator. I have a MacBook Pro..
Any thoughts???
Thanks,
ElenaChances are the buttons are merely behind the Control Panel or your'e simply in Full Screen Mode.
If your document is behind the Control panel, tap the Tab key to hide all panel, then move the document down so it's not behind the control panel.
If you are in Full Screen Mode, tap the F key on the keyboard until you see the buttons again. -
I have assisive touch so I cannot use power button on top but my phone wont turn on I tried plugging it in and pressing the home button but nothing is working?
please help- Connect to computer and it it shows in iTune restore via iTunes
- Then try letting the battery fully drain. After charging for an hour try the reset (both buttons) and connecting to computer and restore. -
My little scroll button on top of my older model A1197 mouse.
My little scroll button on top of my older model A1197 mouse works only intermittantly and usually, if at all, only in one direction. ??
This is usually caused by debris building up between the rollerball and the rollers underneath. Sometimes you can free this up by turning the mouse upside down and rubbing the rollerball vigorously on a sheet of paper.
Maybe you are looking for
-
I have music on one computer but need to move to another
I am sure this has been asked several times but I have not been able to find a concrete answer. I have two laptops. The original one has tons of songs that have not been purchased through itunes but instead downloaded from CD's and an Itunes account
-
IPad - view multi-layer PDF?
On an iPad, how can I view just the text layer of a multi-layer PDF? I have a PDF which has 4 layers. They are all visible at the same time through the Adobe reader app. This is un-readable. How can I select just one layer to view at a time?
-
HT4597 how to purchase OS X Lion
moving from mobile me to Icloud. how do I purchase and which OS X Lion do I upgrade to?
-
Dreamweaver CC 2014 - Where is the .exe file located?
I can easily find the Dreamweaver CC (ver. 13) .exe path, but it's apparently not the same for Dreamweaver CC 2014. Where is the path for it?
-
Documentation for Enhancement spots
Hi experts! I need some advice to my simple problem. I checked one of our custom Z* function modules with 'Where Used' icon, and it shows that it's used in two different enhancement implementations. Those are: LMRMPU05 633 E