jframe

True Full Screen JFrame/Swing Application in Mac OSX

有些话、适合烂在心里 提交于 2019-11-28 13:01:55
I'm working on application and I'm making the GUI with Swing. I would like my application to be fullscreen. I can easily set the size of the window however I have not been able to make the application truly fullscreen (IE With the apple menu bar and dock hidden). All the answers I have found online don't seem to work for me. I'm new to Java so any help is appreciated. frame = new JFrame("Test"); frame.setTitle("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel emptyLabel = new JLabel(""); Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); frame.getContentPane

How to paint an arrayList of shapes Java

限于喜欢 提交于 2019-11-28 12:56:13
问题 I am tasked with how to paint an arrayList of shapes in java. I feel i have most of it right, there are two methods i am confused about however the method in ShapeChooserPanel called public void setPoints(int x, int y) Since Xs and Ys are arrays, how would i set the x and y values? And the other is one is the final method in ShapeChooserPanel I cannot find out how to print the Shapes in the array, It should paint the current shape at the place the mouse was clicked. My code is below Main

java JFrame graphics

心不动则不痛 提交于 2019-11-28 12:55:15
I have the following simple code in a JFrame constructor super(name); setBounds(0,0,1100,750); setLayout(null); setVisible(true); g = this.getGraphics(); int[] x =new int[]{65, 122, 77, 20, }; int[] y =new int[]{226, 258, 341, 310}; g.setColor(Color.RED); g.drawPolygon (x, y, x.length); System.out.println(g); I get the output on console as: sun.java2d.SunGraphics2D[font=java.awt.Font[family=Dialog,name=Dialog,style=plain,size=12],color=java.awt.Color[r=255,g=0,b=0]] But no red polygon drawn on JFrame but just the blank JFrame. Why ?? Dont override paint(..) in JFrame Rather add custom JPanel

Can't call a the third page via the 2nd Page

∥☆過路亽.° 提交于 2019-11-28 12:34:54
问题 I'd like to create a software that has three pages: The "Home Page" (That's drawn on a JFrame "frame"), "Page 2" and "Page 3". Pages 2 and 3 are drawn on "frame". One uses a navigation pane that sits on the left side of the page and the main content is held on the right. I'm currently only able to navigate to the 2nd page. The class called to draw page 2 on the JFrame can't seem to call Page three. My code is as follows: // The Home Page package Try; import java.awt.event.ActionEvent; import

How to add an ImageIcon to a JFrame?

旧城冷巷雨未停 提交于 2019-11-28 12:32:20
I'm trying to add an image to one frame but it seems it does not working. The image created by an ImageIcon from the specified file. The image file is in the seam directory the java file exist. import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class image { public static void main(String args[]) { TimeFrame frame = new TimeFrame(); } } class TimeFrame extends JFrame { //Image icon = Toolkit.getDefaultToolkit().getImage("me.jpg"); ImageIcon icon = new ImageIcon("me.jpg"); JLabel label = new JLabel(icon); public TimeFrame(){

drawing simple rectangles on a Jframe in java

女生的网名这么多〃 提交于 2019-11-28 12:17:05
I am extending JFrame like this: public GameFrame() { this.setBounds(30, 30, 500, 500); this.setDefaultCloseOperation(EXIT_ON_CLOSE); initializeSquares(); } private void initializeSquares(){ for(int i = 0; i < 5; i++){ this.getContentPane().add(new Square(i*10, i*10, 100, 100)); } this.setVisible(true); } However, only one square is being drawn on the screen, does anybody know why? also My Square class looks like this: private int x; private int y; private int width; private int height; public Square(int x, int y, int width, int height){ this.x = x; this.y = y; this.width = width; this.height

Using JFrame from another class

主宰稳场 提交于 2019-11-28 12:13:30
问题 Hi I'm small a little issue trying to append some text to a JTextArea from another class within the same package. Below is the main class that pertains to the JFrame: public class Client extends JFrame{ //Static variables private static final String host = "localhost"; private static final int portNumber = 4444; //Variables private String userName; //JFrame Variables private JPanel contentPanel; private JTabbedPane panel_Social; private JPanel jpanel_Social; private JPanel jpanel_Chat;

How can i set a jFrame to be always on top and focuse enabled until it is closed?

≯℡__Kan透↙ 提交于 2019-11-28 12:12:05
There are two different Frames in my program and the second one open when i click the jButton is the first frame,so when the second frame is opened, I want the second frame to be always on top and focused until it is close. user can't be allowed to do anything in the first window until the second window is closed. how can i do this? JFrame frame = new JFrame (); frame.setAlwaysOnTop (true); If you want frame to be always focused, you probably need to use modal dialog instead of JFrame: JDialog dialog = new JDialog (); dialog.setModal (true); dialog.setAlwaysOnTop (true); dialog.setModalityType

Which icon sizes to use with a JFrame's setIconImages() method?

我怕爱的太早我们不能终老 提交于 2019-11-28 11:57:19
Does anyone know which icon sizes to use with the setIconImages() (PLURAL) method for a jFrame so that my app icons display well on all platforms and in all contexts (e.g., window icon, taskbar icon, alt-tab icon, etc.)? I've found an example that uses a 16px-by-16px and a 32px-by-32px image, but do I need to go any bigger? To test, I have also tried adding 64px and 128px versions to the List passed to setIconImages(), but these do not seem to be used on my Windows 7 machine. However, I cannot test easily on other machines, so am wondering if anyone knows which sizes I should include? Alan

JFrame On Close Operation

老子叫甜甜 提交于 2019-11-28 11:56:29
I was wondering if there is a way, by clicking on the "X", to let the program perform some code before closing the JFrame. The setDefaultCloseOperation() method takes only an integer. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); You might be interested in using a WindowListener . The WindowListener tutorial . this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ int i=JOptionPane.showConfirmDialog(null, "Seguro que quiere salir?"); if(i==0) System.exit(0);//cierra aplicacion } }); Ryan Stewart @Jeffrey has a good answer, but you should consider what you're