How to disable PDF print options using JWebBrowser - java

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; }");

Related

Jxbrowser doesn't show up

I'm using java swing editor
created a frame dropped a tappedpane on it
then dropped 4 panels, so I have 4 taps
the panel that I need to view the browser on is jpanel3
so I dropped a button and wrote this code inside of it
when I run the program and press that button I get no errors just no view
imported everything correctly and the license is valid
enter code here
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
jPanel3.add(view);
browser.loadURL("https://google.com");
}
I suppose the issue is in default FlowLayout in jPanel3. Please try the following solution:
jPanel3.setLayout(new BorderLayout());
jPanel3.add(view, BorderLayout.CENTER);

Adding Webcam panel to existing jPanel

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.

jOptionPane dont show on top windows. Java 1.4

jOptionPane dont show on top windows.
I've read that using
JFrame frmOpt = new JFrame();
frmOpt.setVisible(true);
frmOpt.setLocation(100, 100);
frmOpt.setAlwaysOnTop(true);
should be enough, but the problems is that I'm using Java 1.4 and 'setAlwaysOnTop' does not exists.
so....is there a way to solve this situation?
thanks in advance.
EDIT: Here is what I'm doing:
JFrame frmOpt = new JFrame();
frmOpt.setVisible(false);
response = JOptionPane.showOptionDialog(frmOpt,message,mens, 0,JOptionPane.OK_CANCEL_OPTION,null,options,null);
First I create a JFrame, then I create a new JOptionFrame setting the JFrame.
And it still shows at the back. Notice I do not use setAlwaysOnTop because of Java 1.4

java clickable-through non transparent Component in a transparent clickable-through jframe

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.

How to add a jasper preview into a JPanel

I have created a small report using jasper reports and I previewed it using the jasper viewer as below,
con = JDBCConnectionPool.getInstance().checkOut();
String fileName = getClass().getClassLoader().getResource("com/bio/ofm/mnu/views/reports/jasperReports/repAuditReport.jrxml").getFile();
JasperReport report = JasperCompileManager.compileReport(fileName);
JasperPrint print = JasperFillManager.fillReport(report, null, con);
JasperViewer viewer = new JasperViewer(print);
viewer.setVisible(true);
But I need to show this report in a JPanel so, I tried as,
JasperViewer.setDefaultLookAndFeelDecorated(true);
JRViewer jrv = new JRViewer(print);
jrv.setPreferredSize(new Dimension(getSize()));
JScrollPane reportScroll = new JScrollPane(jrv);
panel1.add(reportScroll);
but the report is not showing as I expected, please explain what is the correct way to add a jasper preview in to a JPanel.
JasperViewer extends JFrame, and you don't want to add a JFrame to a JPanel. You could perhaps add the JasperViewer's contentPane to the JPanel. The other issues I've discussed in a comment still remain unresolved:
What layout manager is panel1 using? Are you adding the JScrollPane to the JPanel after the GUI has been displayed? If so, do you call revalidate() and repaint() on the JPanel after the addition?
this my code and it works
JRViewer jr=new JRViewer(print);
jPanel1.setLayout(new BorderLayout());
jPanel1.repaint();
jPanel1.add(jr);
jPanel1.revalidate();

Categories

Resources