Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-27-2008, 11:19 PM
Member
 
Join Date: May 2008
Posts: 20
nick2price is on a distinguished road
Java GUI layout
I am creating a GUI application. I have a background image and a title at the top of the page. At the bottom, i want to place to JButtons next to each other. This is my code
Code:
import java.awt.image.BufferedImage; import java.io.IOException; import javax.swing.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.io.File; import javax.imageio.ImageIO; public class TitlePage extends JPanel { private static final String FILE_PATH = "C:\\Documents and Settings\\Maureen\\Desktop\\java coursework\\nina\\yr3 work\\olympic.png"; private JButton registErJButton; private JButton logInJButton; private BufferedImage image = null; public TitlePage() { try { image = ImageIO.read(new File(FILE_PATH));// load the image } catch (IOException e) { e.printStackTrace(); } // set up the JPanel. JLabel titleLabel = new JLabel("LONDON 2012"); titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 48)); titleLabel.setForeground(Color.blue); JPanel titlePanel = new JPanel(); titlePanel.setOpaque(false); titlePanel.add(titleLabel); registErJButton = new JButton(); registErJButton.setText( "REGISTER" ); registErJButton.setFont(new Font( "Default", Font.BOLD, 16 ) ); registErJButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { registErJButtonActionPerformed( event ); } } ); logInJButton = new JButton(); logInJButton.setText( "LOGIN" ); logInJButton.setFont(new Font( "Default", Font.BOLD, 16 ) ); logInJButton.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent event ) { logInJButtonActionPerformed( event ); } } ); setPreferredSize(new Dimension(800, 590)); setLayout(new BorderLayout()); add(titlePanel, BorderLayout.NORTH); //THIS IS WHERE MY PROBLEM LIES //FIRST BUTTON DISPLAYS, I NEED THE SECOND BUTTON NEXT OR ONTOP OF IT JPanel pan = new JPanel(new FlowLayout()); registErJButton.setPreferredSize(new Dimension(200,50)); pan.add(registErJButton); add(pan, BorderLayout.SOUTH); /* JPanel pan1 = new JPanel(new FlowLayout()); logInJButton.setPreferredSize(new Dimension(200,50)); pan1.add(logInJButton); add(pan1, BorderLayout.LINE_START); */ } protected void paintComponent(Graphics g) //overriding paint method { super.paintComponent(g); if (image != null) { g.drawImage(image, 104, -100, this); //applying my image } } private static void createAndShowUI() { JFrame frame = new JFrame("Nerkesa Pignatelli"); frame.getContentPane().add(new TitlePage()); // adding the JPanel to the JFrame here frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } private void registErJButtonActionPerformed( ActionEvent event ) { } private void logInJButtonActionPerformed( ActionEvent event ) { } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } }
I can place one button at the bottom using SOUTH. How do i place another button next to this or stacked above it? I know i have to use a different layout style, maybe grid, but i not sure how and the tutorials are hard for me to follow.
cheers
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-27-2008, 11:28 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
put a jpanel in the south region then add the buttons you want into it. Look up the api if your confused.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-27-2008, 11:42 PM
Member
 
Join Date: May 2008
Posts: 20
nick2price is on a distinguished road
Still very confused. API always confuses me.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get layout information from pdf using java aravind730 Java Tips 0 02-09-2008 08:59 PM
SWT Layout JavaForums Java Blogs 0 12-31-2007 06:53 PM
website java button layout abcdefg AWT / Swing 0 12-25-2007 06:44 PM
JGraph Layout Pro 1.4.0.3 levent Java Announcements 0 07-31-2007 08:43 PM
Use the Layout in java lenny AWT / Swing 2 07-26-2007 09:20 PM


All times are GMT +3. The time now is 12:02 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org