473,327 Members | 1,930 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,327 software developers and data experts.

Graphical User Interface (GUI) Probelm

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.io.*;
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.util.Scanner;
  7.  
  8. public class solano extends JFrame{
  9.  
  10. private JLabel letterL ,countL, PercentageL;
  11.     private JTextArea display;
  12.     private JButton exitB;
  13.     private ExitButtonHandler ebHandler;
  14.  
  15.     private static final int WIDTH = 600;
  16.     private static final int HEIGHT = 600;
  17.  
  18.     private static final int SIZE1 = 300;
  19.     private static final int SIZE2 = 20;
  20.  
  21.     public solano(){
  22.  
  23.         letterL= new JLabel("Letter",SwingConstants.CENTER);
  24.         countL =  new JLabel("Count",SwingConstants.CENTER);
  25.         PercentageL =  new JLabel("Percentage",SwingConstants.CENTER);
  26.  
  27.         display = new JTextArea(26,3);
  28.  
  29.         //window
  30.         setTitle("Text Character Count");        
  31.         Container pane = getContentPane();
  32.         pane.setLayout(null);
  33.         letterL.setLocation(-70,1);
  34.         countL.setLocation(85,1);
  35.         PercentageL.setLocation(250,1);
  36.  
  37.         exitB = new JButton("Exit");
  38.         ebHandler = new ExitButtonHandler();
  39.         exitB.addActionListener(ebHandler);    
  40.  
  41.         display.setLocation(SIZE2,SIZE2);
  42.         letterL.setSize(SIZE1,SIZE2);
  43.         countL.setSize(SIZE1,SIZE2);
  44.         PercentageL.setSize(SIZE1,SIZE2);
  45.         display.setSize(500,500);
  46.  
  47.         exitB.setSize(100,SIZE2);
  48.  
  49.  
  50.         pane.add(letterL);        
  51.         pane.add(countL);        
  52.         pane.add(PercentageL);    
  53.             pane.add(exitB);
  54.         pane.add(display);
  55.  
  56.         display.setEditable(false);
  57.  
  58.         setSize(WIDTH, HEIGHT);
  59.         setVisible(true);
  60.         setDefaultCloseOperation(EXIT_ON_CLOSE); 
  61.  
  62. private class ExitButtonHandler implements ActionListener
  63.     {
  64.         public void actionPerformed(ActionEvent e)
  65.         {
  66.             System.exit(0);
  67.         }
  68.     }
  69.   public static void main(String[] args)throws FileNotFoundException
  70.         {
  71.     solano Count = new solano();
  72.  
  73.     }
  74.  
I did not put all of my codes..
Everytime I run my program the Exit Button is covering the Letter JLabel
I want to make the Exit Button be on the buttom of my GUI
How will I do that?
Sep 19 '08 #1
7 1278
JosAH
11,448 Expert 8TB
[code]Everytime I run my program the Exit Button is covering the Letter JLabel
I want to make the Exit Button be on the buttom of my GUI
How will I do that?
That's what you get for not using an appropriate LayoutManager. For now you
can explicitly set the location of your exit button. You only set its size now.

kind regards,

Jos
Sep 19 '08 #2
Nepomuk
3,112 Expert 2GB
Change
Expand|Select|Wrap|Line Numbers
  1. pane.add(exitB);
to
Expand|Select|Wrap|Line Numbers
  1. pane.add(exitB,BorderLayout.SOUTH);
and it should end up at the bottom of your pane. Also, you probably should read the Sun LayoutManager Tutorial - LayoutManagers make Life much easier.

Greetings,
Nepomuk
Sep 19 '08 #3
JosAH
11,448 Expert 8TB
Change
Expand|Select|Wrap|Line Numbers
  1. pane.add(exitB);
to
Expand|Select|Wrap|Line Numbers
  1. pane.add(exitB,BorderLayout.SOUTH);
and it should end up at the bottom of your pane.
That'd only work if there *were* actually a BorderLayout manager installed.

kind regards,

Jos
Sep 19 '08 #4
That's what you get for not using an appropriate LayoutManager. For now you
can explicitly set the location of your exit button. You only set its size now.

kind regards,

Jos
Thank you Jos..you made my day!!
keep it up!! and for those who answer this forum..
I thank you all!!
Sep 19 '08 #5
Nepomuk
3,112 Expert 2GB
That'd only work if there *were* actually a BorderLayout manager installed.
Correct me if I'm wrong, but BorderLayout is the default LayoutManager, so a BorderLayout manager is installed, isn't it? In the code for the BorderLayoutDemo in the BorderLayout Tutorial it says:
Expand|Select|Wrap|Line Numbers
  1. //Use the content pane's default BorderLayout. No need for
  2. //setLayout(new BorderLayout());
So, shouldn't it work although no LayoutManager was chosen here? They don't choose one in that example.

Greetings,
Nepomuk
Sep 19 '08 #6
JosAH
11,448 Expert 8TB
Correct me if I'm wrong, but BorderLayout is the default LayoutManager, so a BorderLayout manager is installed, isn't it?
Yup, normally it is but see what the OP did in line #32 (see above)

kind regards,

Jos
Sep 19 '08 #7
Nepomuk
3,112 Expert 2GB
Yup, normally it is but see what the OP did in line #32 (see above)
Ah, right. Well. Not good. (Although line 32 wasn't that easy to find with the new code display...)

Greetings,
Nepomuk
Sep 20 '08 #8

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

Similar topics

0
by: Jesper | last post by:
I know that user interface library questions come up on this list every now and then. I've lurked here for a while and also searched google for anything that would fit my needs but haven't found...
2
by: ·sÂA¤H | last post by:
I am doing a XML-based workflow management system in Final year project. I wanted to develop a GUI (drag and drop graphic) to define the rule of workflow and save it to XML. How can I generate...
1
by: John F. | last post by:
I want to write a client app in Python using wxWindows that connects to my FreeBSD server via SSH (using my machine account credentials) and runs a python or shell script when requested (by...
1
by: Alexander Muylaert | last post by:
Hi I'm in need of a graphical engine for custom-made-GUI. I don't mind writing it myself, it's fun, but I need it to run on Pocket and PC. What technology can I use best in .net. I don't...
5
by: John Smith | last post by:
Hello Coould please any one to help me to find good graphical controls to create GDI in ASP.NET. Some related websites also really appreciated Thanks in Advance John
3
noylec
by: noylec | last post by:
Hi... I'm new in Java programming. Can you please help me in creating a program using GUI (specifically, using swing)? Here is the problem given: Create a program using GUI (swing) that will ask...
3
by: psbasha | last post by:
Hi, I would like to call the same aplication executable with and without Graphical User Interface. Requirement: With Tkinter User interface,user can give the inputs to run the application (...
6
by: psbasha | last post by:
Hi , Currenty I am storing the Graphical User Interface options in a string memeber variable of a class as show below: SampleCode Tkinter Modules ( Graphical User Interface):...
8
by: r0g | last post by:
Hi There, I'm trying to migrate a locally hosted page from windows to a private Ubuntu development server and one of the key bits of functionality (which used to work fine in Windows) was the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.