Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

GUI....Controlling Control Buttons ....

Thread view: 
Sameer - 27 Feb 2005 07:13 GMT
Related to java GUI
------------------------

I have designed a frame which contains a TextArea ,TextField and a
JButton.
It is going to act as a Personal Messages Window in a chatting program.
The size of the frame is set to 300 X 300.
When I start the JFrame instance it shows the Window but does not show
any component, i have to strech it little bit to show all the
components.

To avoid this, I execute a pack() routine on the frame, but then
all the components of the frame gets collected in one part of the
frame.
This is because there is not content in the TextArea and TextField.
I want to display the frame in full form i.e. having size 300 X 300 all
the time. I know that this is happening due to the routine pack().

How to avoid this so as to display a full window?

Can I design a frame with Close button only i.e. without Minimize and
Maximize button? Is it possible to control display of Control buttons
in Swing?

Related to Thread Issues
-------------------------------
I open a new JFrame in a new Thread from a java program (which is also
a JFrame).

The class definition for this new JFrame application to be opened is

public class Chat extends JFrame implements Runnable {
.........
}

When i dispose the Frame, will this new thread be get killed?
Or it continue to use system resources?

How to kill a particular thread from a JVM when there are so many
threads running simeltaneously?

-Sameer
Dirk Starke - 28 Feb 2005 08:19 GMT
Hello Sameer,

> I have designed a frame which contains a TextArea ,TextField and a
> JButton.
[quoted text clipped - 8 lines]
> [...]
> How to avoid this so as to display a full window?

I guess you are setting the sizes of the Java components. I do not
prefer this way of GUI construction. May I advise you to set the
number of columns and rows your textarea/-field should be able to show
(see methods JTextArea.setColumns(int) and .setRows(int))?

You could use a BorderLayout to construct the main frame with the
textarea in the center part and a panel with the textfield and the
button in the southern part.

If you have setup the layout of the frame correctly you can call
pack() and your frame will be sized as desired (see
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html).

> Can I design a frame with Close button only i.e. without Minimize and
> Maximize button? Is it possible to control display of Control buttons
> in Swing?

You could use a JDialog. Else this might help
http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html#setDefault
LookAndFeelDecorated
.

> Related to Thread Issues
> -------------------------------
[quoted text clipped - 9 lines]
> When i dispose the Frame, will this new thread be get killed?
> Or it continue to use system resources?

I think the thread will be killed when run() exits.
I hope you know that GUI interaction has to be done from the event
dispatching thread (see
http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html).

> How to kill a particular thread from a JVM when there are so many
> threads running simeltaneously?

Just let the thread know that he has to finish its run-method.

Greetings
    Dirk
John McGrath - 28 Feb 2005 11:16 GMT
> I open a new JFrame in a new Thread

You should only be opening a new Frame from the event dispatch thread.  If
you open it from a different thread, it may appear to work, but somewhere
down the road, your program may hang when it does this.  You can open the
frame safely using EventQueue.invokeLater().

Signature

Regards,

John McGrath

Dirk Starke - 28 Feb 2005 14:42 GMT
Hi,

> [...] You can open the
> frame safely using EventQueue.invokeLater().

or
 - SwingUtilities.invokeLater(Runnable doRun) or
 - SwingUtilities.invokeAndWait(Runnable doRun)

Greetings
    Dirk
John McGrath - 28 Feb 2005 21:21 GMT
> > frame safely using EventQueue.invokeLater().
>
> or
>   - SwingUtilities.invokeLater(Runnable doRun) or
>   - SwingUtilities.invokeAndWait(Runnable doRun)

I cannot think of a situation where you would want to use invokeAndWait()
to display a JFrame.  There may be some, but in most cases I think the
better approach would be to use invokeLater().

Of course, you can use the SwingUtilities versions of these methods, but
there is not much point to that, unless you are writing code for JDK 1.1
using the JFC 1.1 add-on package.  The methods were added to EventQUeue
in Java 1.2,and since Java 1.3, the implementation of the SwingUtilities
methods has just called the EventQueue methods.  Here is the code from
the current JDK:

   public static void invokeLater(Runnable doRun) {
       EventQueue.invokeLater(doRun);
   }

   public static void invokeAndWait(final Runnable doRun)
       throws InterruptedException, InvocationTargetException
   {
       EventQueue.invokeAndWait(doRun);
   }

Signature

Regards,

John McGrath

Dirk Starke - 01 Mar 2005 08:31 GMT
Hello John,

you are right.
I just wanted to draw Sameers attention to this class. I prefer to use
classes of the package javax.swing when working with Swing. It might
come a time, when the bodies of those methods do not use the class
EventQueue anymore.

Regards,
   Dirk


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.