My application uses the full screen mode automatically when it launches, and it displays correctly with 1024x768 resolution, but when I have tested the same app in 1366x768 the bottom part disappears. the full screen mode setting looks like this :
//********************* Full Screen Parameter *****************
Toolkit tk = Toolkit.getDefaultToolkit();
setBounds(new Rectangle(new Point(0, 0), tk.getScreenSize()));
setUndecorated(true);
setVisible(true);
Have you tried using setLocation()? For example
setLocation(0,0);
setSize(tk.getScreenSize());
setUndecorated(true);
setVisible(true);
Related
I'm using The DJ Project to open PDF files into JFrame.
Using the next code:
JPanel panel = new JPanel();
setContentPane(panel);
JWebBrowser browser = new JWebBrowser();
browser.setBarsVisible(false);
browser.setStatusBarVisible(false);
browser.print(false);
browser.setPreferredSize(new Dimension(800,600));
panel.add(browser);
browser.navigate("C:\\Users\\MyUser\\Desktop\\acta.pdf");
pack();
setVisible(true);
setPreferredSize(new Dimension(800,600));
And is loading the PDF file, but I want to disable the next options:
The print and Save option. I know that is rendering over a Web Browser.
Is posible remove those options using java ?
The only way that I already found, is disabling all the components and interactions, with:
browser.getNativeComponent().setEnabled(false)
Or disabled all the right clicks, for example:
webBrowser.executeJavascript("document.oncontextmenu = function functionName(){ return false; }");
I'm using NetBeans and I made basic layout with jPanel in the middle of it. Now I would like to add Webcam panel in this jPanel.
Here's example how to get frames from webcam and display it in new window. It's working fine.
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setDisplayDebugInfo(true);
panel.setImageSizeDisplayed(true);
panel.setMirrored(true);
JFrame window = new JFrame("Test webcam panel");
window.add(panel);
window.setResizable(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
But when I tried to display it in my existing jPanel it's not working. Webcam screen is not visible. Here's my code:
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setDisplayDebugInfo(true);
panel.setImageSizeDisplayed(true);
panel.setMirrored(true);
jPanel5.add(panel);
jPanel5.setVisible(true);
I call all of this in my main class constructor. Just after other netbeans componenst are loaded. When I add example it's working good but then my main layout is loaded and webcam screen in another window. I would like to get it in the same window.
I have seen other topics about adding image to jPanel but it's not working with capturing movie from webcam.
Thanks for help.
But when I tried to display it in my existing jPanel it's not working.
When you add components to a visible GUI the basic code is:
panel.add(...);
panel.revalidate(); // invoke the layout manager
panel.repaint(); // paint components
All component have a default size of (0, 0) when created so there is nothing to paint. You need to invoke the layout manager so the component is given a size/location.
I changed a little my application and now in the middle of main windows is JTabbedPane and I found a solution to my problem. Instead of making Tabs using NetBeans window designer I made it with code.
I made empty JTabbedPane in Netbeans and then add this to code:
final JPanel jPanelCamera = new JPanel();
jTabbedPane1.addTab("Camera", jPanelCamera);
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
WebcamPanel webcamPanel = new WebcamPanel(webcam);
webcamPanel.setFPSDisplayed(true);
webcamPanel.setDisplayDebugInfo(true);
webcamPanel.setImageSizeDisplayed(true);
webcamPanel.setMirrored(true);
jPanelCamera.add(webcamPanel);
jPanelCamera.getParent().revalidate();
System.out.println("Camera OK");
I have no idea why earlier when I made component using NetBeans designer it was't working but now it's working good. I think if someone would add this not to JTabbedPane, but to JPanel should also make this panel with code. Not with Netbeans designer and then it should work.
The following code results in a transparent window in Windows (8.1), but an opaque window in Ubuntu (14.04). How can I achieve the transparent window with the red outline in Ubuntu 14.04?
My goal is to create an undecorated window with 'rounded (transparent) edges', so the setOpacity() method won't help since that will affect the full window, even though it does work on both operating systems.
public static void main(String[] args) {
JFrame f = new JFrame();
f.setUndecorated(true);
f.setBackground(new Color(0,255,0,0));
f.setSize(512, 512);
f.add(new JPanel() {
#Override
protected void paintComponent(Graphics g) {
g.setColor(Color.RED);
g.drawRect(0, 0, 511, 511);
}
});
f.setVisible(true);
}
I've found the source of the problem. It is related to having a multi-monitor setup in Ubuntu. Regardless, here's the solution--which will cause it to work on the favored monitor:
Add the following code before the setVisible() call:
f.setLocationRelativeTo(null);
I think the reason it failed is because the frame may have been rendered on the secondary monitor first (due to different resolutions per monitor?), which may have resulted in this drawing error.
Thank you all for your input. It is greatly appreciated! :)
Not all window mangers on linux support transparent windows. If a window manager does not support transparent windows t will show up as a normal window. So check first that your window manager supports transparent windows (with GraphicsDevice#isWindowTranslucencySupported()).
OS = Ubuntu; JDK = 1.7.0_10
General:
What I want is something commonly available as desktop widget (e.g. annotate for compiz or gromit), is there a way to do it in Java?
I want to create one jframe or window to be full-screen, transparent, clickable-though and always on top.
Inside the jframe I want to add/remove components (text, images, rectangles..) to be positioned on a specific point of the screen. Those component should be non-trasparent and always on top. If possible they should allow to click through.
Example:
I have several app opened on my desktop.
I want to automatically draw a box around window which is on focus drawing a rectangle around the window, the area of the rectangle should be transparent and clickable-thsough in order to allow me to use my application.
Problems:
I can create a transparent frame which stays on top but is not clickable-through, but The component what I will ad to the frame will be in any case transparent.
JFrame frame = new JFrame("MyFrame");
frame.setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.setLocation(0,0);
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);
frame.setAlwaysOnTop(true);
frame.setAlwaysOnTop(true);
//frame.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", false); //apple
frame.getContentPane().setLayout(new BorderLayout());
System.setProperty("sun.java2d.noddraw", "true");
AWTUtilities.setWindowOpaque(frame, false);
AWTUtilities.setWindowOpacity(frame, 0.0f);
JLabel label = new JLabel("Hello NOT transparent label");
label.setOpaque(true);
label.setBackground(new Color(255, 0, 0));
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
I can make the frame transparent and clickable-through by setting the IconImage with a transparent image loaded from URL.
This works if the image is loaded from an URL but not if I load the image from a local file (why?!?).
Also in this case, when I add a component to the frame is not displayed.
try {
frame.setIconImage(Toolkit.getDefaultToolkit().getImage(new URL("http://i.imgur.com/xtZK0.png")));
} catch (MalformedURLException e) {e.printStackTrace();}
I tried to add a JFXPanel but no success, I tried adding the component to the GlassPane but no success..
After one week of intensive tests and search I hope someone can give me a solution or the right hint.
Thanks.
New to NetBeans and just noticed that in the File >> Project Properties >> Application dialog there is a text field labeled Splash Screen that allows you to specify a path to an image that you would like displayed when your program is launching.
I want to customize the way my splash screen works (adding a progress bar, etc.) and would like to code it from the ground up but don't know where to start. What are the best practices for Java/Swing-based splash screens?
Thanks for any and all input!
The project properties -> Application -> Splash Screen allows you to add an image to an application. This property sets a value in the MANIFEST.MF called SplashScreen-Image: e.g. SplashScreen-Image: META-INF/GlassFish316x159.jpg This property will automatically cause the image to display as a splash screen. It does not work inside NetBeans, and must be run outside the IDE.
There is a tutorial Splash Screen Beginner Tutorial that details how to use it more detail. The tutorial was done for NetBeans 6.8, but will work on 7.2.1 which is the latest at the time of this post.
I'm not sure how NetBeans does it, but Splash Screens are supported by the JRE since version 6. See http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/
Splash screen is just a instance of java.awt.Window or undecorated javax.swing.JFrame.
To create window just say new Window(null), then set size and position (using tookit you can calculate where the screen center is) and then say window.setVisible(true)
Due to this is your own window you can do what you want: set layout, image, add process bar to the SOUTH etc.
You can also use JFrame: new JFrame().setUndecorated(true)`
There are a couple of ways to do this.
To do a simple splash screen (an image) you can specify this in the command line of you java application.
Here is a simple example
java -splash:<file name> <class name>
However, if you want a progress bar, you are going to have to do something a little more complicated, and write some code yourself. This is done in the following way.
Create a JWindow (or Window or undecorated JFrame) component with your splash screen elements
Set it to visible
Do the rest of your Swing GUI startup code
Set your JFrame to visible, then immediately follow with setting the JWindow to visible(false)
This should show the splash almost immediately, and then hide once the your application is fully loaded.
To see some splash screen code, take a look here. The implementation in the link only shows how to achieve what you can with the -splash command, but it will give you a good start to also include the progress bar that you requested.
I hope this helps you, it is a small example of how to create yourself a simple splash screen using a dummy Progress Bar:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class SplashScreen extends JWindow
{
private static JProgressBar progressBar = new JProgressBar();
private static SplashScreen execute;
private static int count;
private static Timer timer1;
public SplashScreen()
{
Container container = getContentPane();
container.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new javax.swing.border.EtchedBorder());
panel.setBackground(new Color(255,255,255));
panel.setBounds(10,10,348,150);
panel.setLayout(null);
container.add(panel);
JLabel label = new JLabel("Hello World!");
label.setFont(new Font("Verdana",Font.BOLD,14));
label.setBounds(85,25,280,30);
panel.add(label);
progressBar.setMaximum(50);
progressBar.setBounds(55, 180, 250, 15);
container.add(progressBar);
loadProgressBar();
setSize(370,215);
setLocationRelativeTo(null);
setVisible(true);
}
public void loadProgressBar()
{
ActionListener al = new ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
count++;
progressBar.setValue(count);
if (count == 50){
timer1.stop();
execute.setVisible(false);
//load the rest of your application
}
}};
timer1 = new Timer(50, al);
timer1.start();
}
public static void main (String args[]){
execute = new SplashScreen();
}
}
Cheers!
Also consider to build your application on top of the NetBeans Platform (a Swing-based RCP). One of the many benefits: it comes with a customizable splash screen with progress bar.
Sample progress bar:
http://platform.netbeans.org/tutorials/nbm-paintapp.html#wrappingUp
Port a Swing application to the NetBeans Platform:
http://platform.netbeans.org/tutorials/60/nbm-porting-basic.html
Further links:
http://netbeans.org/features/platform/index.html
http://netbeans.org/features/platform/all-docs.html
If your application is build using NetBeans Platform, then here's a tutorial about splash screen customisation: http://wiki.netbeans.org/Splash_Screen_Beginner_Tutorial
There is a sample Javafx equivalent of Splash screen. However this splash screen is basically a java swing applet that is called from javafx to be displayed to the user and simulates more or less eclipse and netbeans splash screen using progress bar and titles for the loaded contents. This is the link.
You must be able to get the code and separate out the splash screen code written in java swings and use it for yourself.
This is a custom java swings splash screen. and hence to center the splash screen it uses the traditional
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = l.getPreferredSize();
setLocation(screenSize.width / 2 - (labelSize.width / 2),
screenSize.height / 2 - (labelSize.height / 2));