How can I get screen resolution in java?

You can get the screen size with the Toolkit.getScreenSize() method. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double width = screenSize.getWidth(); double height = screenSize.getHeight(); On a multi-monitor configuration you should use this : GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int width = gd.getDisplayMode().getWidth(); int height = gd.getDisplayMode().getHeight(); If you want to get the screen resolution in DPI you’ll have … Read more

Java Desktop application: SWT vs. Swing [closed]

Pros Swing: part of java library, no need for additional native libraries works the same way on all platforms Integrated GUI Editor in Netbeans and Eclipse good online tutorials by Sun/Oracle Supported by official java extensions (like java OpenGL) Cons Swing: Native look and feel may behave different from the real native system. heavy components … Read more

How do I set a JLabel’s background color?

Use label.setOpaque(true); Otherwise the background is not painted, since the default of opaque is false for JLabel. From the JavaDocs: If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through. For more information, read the Java … Read more

Java Look and Feel (L&F) [closed]

There is a lot of possibilities for LaFs : The native for your system The nimbus LaF Web LaF The substance project (forked into the Insubstantial project) Napkin LaF Synthetica Quaqua (looks like aqua from MacOS X) Seaglass JGoodies Liquidlnf The Alloy Look and Feel PgsLookAndFeel JTatoo Jide look and feel etc. Resources : Best … Read more

JComboBox Selection Change Listener?

It should respond to ActionListeners, like this: combo.addActionListener (new ActionListener () { public void actionPerformed(ActionEvent e) { doSomething(); } }); @John Calsbeek rightly points out that addItemListener() will work, too. You may get 2 ItemEvents, though, one for the deselection of the previously selected item, and another for the selection of the new item. Just … Read more

Providing white space in a Swing GUI

Using various LayoutManagers one can provide spacing between various components. 1.) BorderLayout : Overloaded Constructor : BorderLayout(int horizontalGap, int verticalGap) Getter and setter methods For Horizontal Spacing : BorderLayout.getHgap() and BorderLayout.setHgap(int hgap) For Vertical Spacing : BorderLayout.getVgap() and BorderLayout.setVgap() 2.) FlowLayout : Overloaded Constructor : FlowLayout(int align, int hgap, int vgap) Getter and setter methods … Read more

Copying text to the clipboard using Java

This works for me and is quite simple: Import these: import java.awt.datatransfer.StringSelection; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; And then put this snippet of code wherever you’d like to alter the clipboard: String myString = “This text will be copied into clipboard”; StringSelection stringSelection = new StringSelection(myString); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)