jframe

JFrame not showing a picture

十年热恋 提交于 2019-11-28 00:31:21
Following is the code I have so far: All the imports are correct. I'm sure. :D When I run the program, all I get is a blank frame, without the picture. It should show up. public class WindowPractice extends JFrame { final static int width= 800; final static int height= 400; int x; int y; Image steve; Dimension gamesize= new Dimension (width, height); public WindowPractice(){ setTitle ("Hangman"); setSize (gamesize); setVisible (true); setResizable (false); setLocationRelativeTo (null); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); } public static void main (String[] args) { new

JFrame the same shape as an Image / Program running in background

左心房为你撑大大i 提交于 2019-11-28 00:27:43
My question is simple, the solution surely not. I am looking for a way to shape a JFrame the same as an Image it will be displaying. By shape I mean the shape of the pixels that have an alpha != 0. I've already found a working example using a GeneralPath object, but it created ~110000 "nodes" for an Image of about 500*400, so starting the JFrame took more than 2 minutes, which is definitely not the desired effect, the startup should be in under 2 seconds. Thanks for your time. I personally would ditch the window shape in favor of a transparent window, it's just simpler for what you are trying

Open a new JFrame

丶灬走出姿态 提交于 2019-11-27 23:57:28
I have a main JFrame that has all kinds of panels in it for different functions and people can calculate things in them. I want to open a new JFrame when the user hits the first calculate button and serve as a Output window (Simlar to SPSS output windows if you are familiar with them). The New JFrame will be completely separate and will have its own menu bar ... A simple JDialog is not the way to go here. mKorbel can't resist, simple disagree with answers JFrame frame = new JFrame( ); and frame.setVisible(true); I want to open a new JFrame when the user hits the first calculate button and

How to remove window box from any java gui

落爺英雄遲暮 提交于 2019-11-27 23:22:39
How do i remove the window box from any java program. Because i want to make it look border-less. I know any jar files running on jre automatically gets a window like this. So i want to know if there is workaround about this. Thanks in advance here is a photo what i want to do exactly See Frame#setUndecorated You could also use a JWindow which is undecorated by default. Check this and this for example uses Updated If you remove the border, you become responsible for moving and resizing of the window... This "basic" example demonstrates how to move a JWindow with the mouse. This makes a "drag

Communication between two different JFrames?

烂漫一生 提交于 2019-11-27 23:17:12
Hello as maybe you have heard about GIMP or something like that which uses different frames As a complete gui so I was wondering how to do such frames communications when both(maybe multiple) frames are loaded in memory and are visible. I have gone through some articles but they were not so satisfactory, if anyone have a good example or tutorial then please share. Regards Alok sharma Basically, it's just a matter of having a reference to frame A in frame B, and a reference to frame B in frame A : public class FrameA extends JFrame { private FrameB frameB; public void setFrameB(FrameB frameB) {

Easier way to make a paint application in java?

一世执手 提交于 2019-11-27 22:55:14
问题 So basically I have some code I was working on a couple of days ago that is kind of like Paint, which allows you to essentially draw on the screen using the mouse. I kind of discovered this property by accident, and I realized that it is really inefficient and i'm wondering if there is a more practical way to do this. There isn't really any reason to give all of my code, but here are the important parts private static void createAndShowGui() { SimpleDraw mainPanel = new SimpleDraw(); MenuBar

Java Drag-n-Drop files of specific extension on JFrame

半腔热情 提交于 2019-11-27 22:34:46
I would like to implement DnD for my application to accept only files of certain extension (eg. wrl). I would like to change the cursor to a drag cursor if the file will be accepted and revert back to normal cursor when the file of wrong extension is drag and dropped. I have been following the following tutorial/example from http://docs.oracle.com/javase/tutorial/uiswing/dnd/toplevel.html The change that I make is in the canImport function public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; }

How do I remove the maximize and minimize buttons from a JFrame?

女生的网名这么多〃 提交于 2019-11-27 22:05:54
I need to remove the maximize and minimize buttons from a JFrame . Please suggest how to do this. import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class Dlg extends JDialog { public Dlg(JFrame frame, String str) { super(frame, str); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); } public static void main(String[] args) { try { Dlg frame = new Dlg(new JFrame(), "No min max buttons"); JPanel panel =

Swing: set JFrame content area size

拈花ヽ惹草 提交于 2019-11-27 21:34:53
问题 I'm trying to make a JFrame with a usable content area of exactly 500x500. If I do this... public MyFrame() { super("Hello, world!"); setSize(500,500); } ... I get a window whose full size is 500x500, including the title bar, etc., where I really need a window whose size is something like 504x520 to account for the window border and titlebar. How can I achieve this? 回答1: you may try couple of things: 1 - a hack: public MyFrame(){ JFrame temp = new JFrame; temp.pack(); Insets insets = temp

How can I remove just the Maximize button from a JFrame?

放肆的年华 提交于 2019-11-27 20:24:27
I have a JFrame and want to remove the maximize button from that. I wrote the code below, but it removed maximize, minimize, and close from my JFrame . JFrame frame = new JFrame(); frame.add(kart); frame.setUndecorated(true); frame.setVisible(true); frame.setSize(400, 400); I want to only remove the maximize button from the JFrame . Make it not resizable: frame.setResizable(false); You will still have the minimize and close buttons. You can't remove the button from a JFrame . Use a JDialog instead. It doesn't have a maximize button. import java.awt.event.WindowAdapter; import java.awt.event