473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Placing components on a background image.

Alright I'm trying to place the textarea on top of the image but right now it displays the textarea below the image, how do i go about doing this.

Expand|Select|Wrap|Line Numbers
  1. import java.awt.Color;
  2. import java.awt.FlowLayout;
  3. import javax.swing.ImageIcon;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JPanel;
  7. import javax.swing.JTextArea;
  8.  
  9. /**
  10.  *
  11.  * @author Hanshawc
  12.  */
  13. public class MyDesk extends JFrame
  14. {
  15.    private JPanel panel;
  16.    private JTextArea questionBox;
  17.  
  18.    public static void main(String[] args)
  19.    {
  20.        MyDesk myDesk = new MyDesk();
  21.    }
  22.  
  23.    public MyDesk()
  24.    {
  25.        this.setTitle("MyDesk Alpha Version: 0.1");
  26.        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  27.        this.setSize(660,525);
  28.        this.setResizable(false);
  29.        this.add(getMainPanel());
  30.        this.setVisible(true);
  31.    }
  32.  
  33.    private JPanel getMainPanel()
  34.    {
  35.        panel = new JPanel();
  36.        panel.setSize(640,480);
  37.        panel.setBackground(Color.WHITE);
  38.        panel.setLayout(new FlowLayout());
  39.        panel.add(getBackgroundImage());
  40.        panel.add(getQuestionBox());
  41.        return panel;
  42.    }
  43.  
  44.    private JLabel getBackgroundImage()
  45.    {
  46.        ImageIcon titleIcon = new
  47.        ImageIcon(getClass().getResource("background.jpg"));
  48.        JLabel titleLabel = new JLabel();
  49.        titleLabel.setIcon(titleIcon);
  50.        return titleLabel;
  51.    }
  52.  
  53.    private JTextArea getQuestionBox()
  54.    {
  55.         questionBox = new JTextArea(getQuestion());
  56.         questionBox.setColumns(20);
  57.         return questionBox;
  58.    }
  59.  
  60.    private String getQuestion()
  61.    {
  62.        String question = "Test question";
  63.        return question;
  64.    }
  65. }
  66.  
Mar 9 '09 #1
2 2352
r035198x
13,262 8TB
See the API specs of the FlowLayout that you are using to find out why that is happening. You could use a GridLayout(2, 1) and add the TextArea first.
Mar 10 '09 #2
JosAH
11,448 Expert 8TB
@r035198x
My guess is that the OP means "on top" in the third dimension, i.e. in front of the image. A JDesktopPane can do it or else the GlassPane can be of help: i.e. it is in front of everything else.

kind regards,

Jos
Mar 10 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: unknown | last post by:
I am trying to place a company logo on a form but try as I will I can not get the transparent parts to stay transparent. Is this even possible? If so what file format does my picture need to be...
3
by: Brenny | last post by:
Hello I'm designing a windows form and form's background image is exist and I added a label and groupbox. There is a spesific image on the form and I want to show this image as label and...
0
by: SamSpide | last post by:
Hi all, I'm trying to place a semi-transparent image (i.e. an image with parts of it were drawn in transparent color) over a playing video, but can't seem to make it work. Instead of the...
6
by: Rob | last post by:
Hello, I'm sure this has come up before. I have need for a collection of all elements/objects in an HTML document that have any kind of an attribute (HTML or CSS) that is making use of a URL to...
4
by: foleyflint | last post by:
Hello, lately I've been trying to make an applet that has a background image and a couple of canvas objects on it holding an image each. I created the class ImageCanvas which extends Canvas adn...
1
nathj
by: nathj | last post by:
Hi, I'm surrently struggling with something I'm certain should be very simple. I'm working on a new web application that requires every user to login before they do anything else. This means...
2
by: vertozia | last post by:
Hey there, ive been having difficulty placing an image, this is my screenshot, and what ive done so far: http://img341.imageshack.us/img341/9894/gridwg2.jpg /** * ConnectFourGUI * Provide...
1
by: caesarkim | last post by:
I have code like this. I want "Hello World" to be placed on top of 'big_icon.gif' image which is width: 179 height: 35px. The following code doesn't work with firefox and IE. The image appears, but...
1
by: desturrr | last post by:
I have been searching all over the sites, but i couldn't manage to get button or any other component on a image panel. There are some codes that says while painting the picture you can show...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.