Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

jframe not moveable

  Asked By: Ludwig    Date: Jun 02    Category: Java    Views: 3741
  

i would like to know is there a way to make the jframe
not moveable.i mean user cannot drag the frame around the screen.i
look through the Jframe API but can't seems to find the method or
have i overlooked it..

Share: 

 

21 Answers Found

 
Answer #1    Answered By: Faiza Mian     Answered On: Jun 02

your problem is strange, why do you want to do this. cmiiw ...
usually someone, try to move the jframe  by dragging it with mouse. so I think,
you could implements/add MouseMotionListener for this. when the frame  was
dragged, you should setLocation(defaultX, defaultY)....
just try it by yourself, I never try this one before.

 
Answer #2    Answered By: Felix Gray     Answered On: Jun 02

indeed it is strange... =)
and yes i do agree with
the suggestion...perhaps
you can implement mouseDragged(MouseEvent e)
of the MouseMotionListener and
instruct it to retain the coordinates
or to actually do nothing...

 
Answer #3    Answered By: Sultana Tabassum     Answered On: Jun 02

.i need to do this because i am trying to do
a screensaver thing.so user  canot drag the frame  around unless he
logs in.thanks for the suggestions,i will try..

 
Answer #4    Answered By: Hollie Hughes     Answered On: Jun 02

I think you must know about Model View Controller (for SWING) more detail to
solve your problem. Is there anyone know, where is the good reference for
Java MVC ? (web reference, I looking for that too)

--

 
Answer #5    Answered By: Jackson Williams     Answered On: Jun 02

For Swing, go to Sun Website or Swing book [Manning
2000] written by Matthew Robinson & Pavel Vorobiev.

Another approach to learn MVC is from UML angle.

 
Answer #6    Answered By: Ethan Evans     Answered On: Jun 02

I just try using MouseMotionListener, and it doesn't work , it only work
inside JFrame . I tried a little trick and I thing this techniques can solve
your problem too ...
You can use WindowFocus event, when the focus was lost, It always send
windowLostFocus ...
I don;t know why requestfocus() doesn't work with frame, so I use
JFrame.show() to 'refresh' & to gain the focus again.

If you don;t want someone to close the frame, just set
JFrame.setDefaultCloseOperation with JFrame Do Nothing On Close.

in JFrame constructor add :

////////////////////////////////////////////////////////////////////////////////\
////////////////

WindowFocusListener listen = new WindowFocusListener()
{
public void windowLostFocus(WindowEvent e) {
System.out.println("Window Focus Listener : focus lost");
// requestFocus();
setLocation(200,300);
show();
}

public void windowGainedFocus(WindowEvent e) {
// do nothing
System.out.println("window focus listener : gain focus ");
}
};

addWindowFocusListener(listen);

////////////////////////////////////////////////////////////////////////////////\
///////////

good luck & I hope this is usefull for you project .

ps : the user  still could drag the window but they cannot leave the
window(frame) until that window was closed (use dispose() method).

 
Answer #7    Answered By: Komal Mohammad     Answered On: Jun 02

true enough, one should somehow be
familiar with the mvc design pattern since
jfc(swing) design is modeled after it.

for your screensaver thing...try using javax.swing.JWindow

 
Answer #8    Answered By: Chau Tran     Answered On: Jun 02

The screensaver program has logic and syntax problems
in it. I did hinted him to recoding and learning.
Hope he does not have the pressure of getting a good
grade instead understand the material.

 
Answer #9    Answered By: Viheke Fischer     Answered On: Jun 02

The following is some demo code that does what you need.
After you append text to your JTextArea, set the CaretPosition to the length of
all the text in the JTExtArea and it will scroll down to the end and you go.
I put it in its own private method  to make it convenient:

private void appendLine(String text){
display.append(text + "\n");
display.setCaretPosition(display.getText().length());
}


********************
import java.awt.*;
import javax.swing.*;

public class TestDisplayScroller extends JFrame{

JTextArea display;

public TestDisplayScroller(){
super("TestDisplayScroller");
}

public static void main (String[] args){
TestDisplayScroller scroller = new TestDisplayScroller();
System.out.println("Test");
scroller.init();
scroller.test();
}

public void test(){
for (int i = 0; i < 100; i++){
appendLine("this is a test to see if the display scrolls down as new
lines are added.");
}
}


public void init(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
display = new JTextArea(20,80);
JScrollPane scrollPane = new JScrollPane(display);
getContentPane().add(scrollPane, BorderLayout.CENTER);
pack();
setLocationRelativeTo(null);
show();
}

private void append(String text){
display.append(text);
display.setCaretPosition(display.getText().length());
}

private void appendLine(String text){
display.append(text + "\n");
display.setCaretPosition(display.getText().length());
}
}

 
Answer #10    Answered By: Jeanette Greene     Answered On: Jun 02

make an executable jar.
running it from a double click is possible in jvm 1.4

 
Answer #11    Answered By: Isabella Campbell     Answered On: Jun 02

That's why the gods invented the equals method  in java.lang.Object

If getName() returns a String then simply do:

if ( getName().equals(nameSearch) ) {
System.out.println("wow. it is working");
}

 
Answer #12    Answered By: Logan Bouchard     Answered On: Jun 02

I am in the process of creating a socket program as well so hopefully we
can help each other.

To start, the readLine() method  is deprecated in the DataInputStream and
they suggest to use the BufferedReader class instead. The next problem is
that the readLine() method will keep reading until it finds a line feed ('
\n') or a carriage return ('\r'), That is why it looks like it is not
doing anything because it has not found either characters yet. Try
changing your code to read a character array to something like this:

char dataFromServer[] = new char[1024];
...
...
...
iReceived = in.read(dataFromServer, 0, 1024);
...
...
...

iReceived = the amount of characters actually read (test for -1 as you had
below)
dataFromServer = where to put the characters
0 = offset to start reading at
1024 = total number of characters to read

You will have to adjust your read to either a larger number or loop until
you have all the data. I hope this helps. Let me know if I didn't explain
it correctly or if you need more help.

 
Answer #13    Answered By: Aidyn Smith     Answered On: Jun 02

Try using grabFocus() on your Dialog component.
eg: Jdialog.grabFocus()

 
Answer #14    Answered By: Abbad Akhtar     Answered On: Jun 02

I tried this also ,
It is not working , since the control is out of java .
I can get the focus after clicking the mouse over the JDialog window .
My requirement is the focus should come automatically to the JDialog window

 
Answer #15    Answered By: Cais Nguyen     Answered On: Jun 02

To generate a Word document u can use
Jakarta POI - Java API To Access any Microsoft Format Files
Word , Excel ,...

 
Answer #16    Answered By: Jaspreet Kapoor     Answered On: Jun 02

Not sure if it is the same problem, but i have simply used:
java -mx???m ProgramName

For example:
java -mx512m ProgramName
and Virtual Machine allocates 512MB for your program.

 
Answer #17    Answered By: Elaine Stevens     Answered On: Jun 02

We use the following in our application

-Xmx400m
-Xms120m

To ensure a good minimum, but stop the application from taking too
much memory. Its seems to be as much art as science as to where these
values can be set to achieve the best possible response.

 
Answer #18    Answered By: Alexis Castillo     Answered On: Jun 02

What Chris means to say is be precise with what you need..
Are you looking for building a online ticketing system or something....

 
Answer #19    Answered By: Dot net Sachin     Answered On: Jun 02

for Tomcat have u set the env var CATALINA_HOME ??

try and look at the batch file u run for wats its actually doing..

 
Answer #20    Answered By: Renee Lane     Answered On: Jun 02

Set env variable - JAVA_HOME

and run startup.bat.

This shld work.

 
Answer #21    Answered By: Volney Fischer     Answered On: Jun 02

The declaration of x in class b overrides the declaration of x in class
a, thus making a.x invisible. If you really want to access a.x, don't
include the line public int x; in the declaration for class b.

 
Didn't find what you were looking for? Find more on jframe not moveable Or get search suggestion and latest updates.




Tagged: