I've searched quite a few threads here but none have helped.
I have a few JFrames and each JFrame should have its own individual cursor, symbolizing which version of the program the user is using.
These files are in /AndroidToolkit/resources. The files are all .cur files, so they're actually proper cursors and not just images.
I've tried a few methods of doing this, but I have succeeded. I've tried using ImageIO, Toolkit, and my last try was:
Cursor cCur = Toolkit.getDefaultToolkit().createCustomCursor(getClass().getResource("../resources/ImpressionCursor.cur").getFile()., null, null);
How can I do this in an easy way, which is easy for other people to understand, without me having to always comment it with 10k lines?
Thanks in advance,
Beats
This is what you need, try this code 100% works for me on Ubuntu 12.04 LTS, it should work for you too:
public static void main(String[] args) {
Toolkit toolKit = Toolkit.getDefaultToolkit();
Image pencil = toolKit.getImage("pencil.gif");
Cursor cursor = toolKit.createCustomCursor(pencil, new Point(0, 0), "Pencil");
JFrame frame = new JFrame("Cursor Test");
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setCursor(cursor);
frame.setVisible(true);
}
this is the link for the gif file click here,
I hope that helps, Salam
Related
I made this aplication on Eclipse for a school project. It's just suppose to run a video when a button is press. In the IDE everything works fine, althought an error occures but doesn't cause any trouble (Will leave it, thought, so if it causes something I want to now.)
Now, when I export the Jar file and try to run it, in the same computer, video doesn't play. What can I do?
JFrame vid = new JFrame();
vid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
vid.setBounds(100, 100, 450, 300);
vid.setVisible(true);
Canvas c = new Canvas();
c.setBackground(Color.BLACK);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(c);
vid.add(p);
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"C:/Program Files/VideoLAN/VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
MediaPlayerFactory mpf = new MediaPlayerFactory();
EmbeddedMediaPlayer emp = mpf.newEmbeddedMediaPlayer(new Win32FullScreenStrategy(vid));
emp.setVideoSurface(mpf.newVideoSurface(c));
emp.toggleFullScreen();
emp.setEnableMouseInputHandling(false);
emp.setEnableKeyInputHandling(false);
String file="/resources/sky.mp4";
emp.prepareMedia(file);
emp.play();
Here is the error code that appears:
[0000000017a2b420] core vout display error: Failed to set on top
Please, help me, as I need the project to work.
Okay, I got to work it around a bit.
As I can't use a URL instead of String, and String doesn't let me do a Class#getResource, I finally decide to run it from a public folder which should not change, in theory, from pc to pc.
So my code end up being:
String file = new File("C:/Users/Public/Videos/sky.mp4").getAbsolutePath();
emp.prepareMedia(file);
emp.play();
While not ideal to pass without guidance, as we will be installing the program, it does the job.
I'm having some problems with charset encodings. I'm using AdvancedRTFEditorKit (free closed source library: http://java-sl.com/advanced_rtf_editor_kit.html).
If I copy some special characters (ěščřžýáíé) from MS Word and paste them into sample delivered with AdvancedRtfEditorKit library, everything works fine. But if I do the same with my really simple SSCCE which uses AdvancedRTFEditorKit, then they appear as just rectangles. Do you know what I'm doing wrong?
This problem only occurs with MS Office products. LibreOffice works fine.
My SSCCE:
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(350, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextPane pane = new JTextPane();
pane.setEditorKit(new AdvancedRTFEditorKit());
frame.add(pane);
frame.setVisible(true);
}
After many changes in my code I figured out there isn't any problem with my app. My problem was just running app directly from NetBeans IDE. I don't know why, but IDE somehow encode/decode interaction with OS.
I want to show an animated gif in my application. I followed the code found here: Show animated GIF
When I run my code I get the MalformedURLException error and my application will not run. Here is what I have that's not working.
The method that calls createVisuals():
private void defaultGUI() {
frame.setTitle("Class Map");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
frame.setBounds(0, 0, frameWidth, frameWidth/2);
frame.getContentPane().setBackground(Color.WHITE);
frame.setUndecorated(true);
try {
Visuals.createVisuals();
} catch (MalformedURLException e) {
e.printStackTrace();
}
frame.pack();
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
}
The method that shows the gif:
public class Visuals {
public static void createVisuals() throws MalformedURLException{
URL cwURL = new URL("src\\images\\classmap_colorwheel-gif.gif");
Icon cwGif = new ImageIcon(cwURL);
JLabel cwIcon = new JLabel(cwGif);
GUI.frame.getContentPane().add(cwIcon);
}
What am I not doing correctly?
EDIT:
laksys pointed out that my URL constuction was wrong and gave a reference to fix it. The problem was that I was not giving the full file location alongside adding File: to the begining of the URL.
URL cwURL = new URL("src\\images\\classmap_colorwheel-gif.gif");
URL cwURL = new URL("File:C:/Users/01526460/Desktop/ClassMap/src/images/classmap_colorwheel-gif.gif");
This caused the exception to disappear, however the gif is not running properly. Only one frame of the gif sequence loads while the others only partially load. The gif is also looping faster than it should.
EDIT 2:
I figured out that the gif was not looping properly because of the way I made it, not because of Java. I used Photoshop CS6 to create a frame animation. When I ran the frame animation at 0 second delay between frames it looked fine in Photoshop. However, when the 0 second delay is interpreted through Java, the gif is actually trying to go 0 seconds between frames. If anyone else encounters this problem make sure the delay between your frames is not set to 0. Java does not automatically control the frame rate of gifs (like many browsers do).
I think your url construction is wrong. It may have protocol, host, port etc., please ref this
Well I was wondering if I could make an icon image for a JFrame. I do know its posible, because, let me say, I am NOT digging the java logo.
Well if I just hava to use a Frame object I will.
Can someone tell me, I know its possible!
Use an ImageIcon.
ImageIcon icon = new ImageIcon( pathToIcon );
yourFrame.setIconImage(icon.getImage());
Good Luck!
First, you have to have an image file on your computer. It can be named anything. For this example, we will call this one "pic.jpg".
Next, you need to include it in the files that your application is using. For example, if you're using NetBeans, you simply click on "Files" in the left hand side of the IDE (not File as in the menu, mind you). Drag the picture's file over to the folder that houses the main package. This will include it for available use in the code.
Inside the method where you define the JFrame, you can create an image like this:
Image frameImage = new ImageIcon("pic.jpg").getImage();
You can now set it as the IconImage for the frame like this:
JFrame frame = new JFrame("Title");
frame.setIconImage(frameImage);
Hope that's helpful.
Note: the reason that the Image object has to be created like this is because Image is abstract and cannot be instantiated by saying new Image();
Props to you, btw, kid. I wish I would have started learning programming when I was your age. Keep at it!
You can do the following.
public Test {
public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.setIconImage(new ImageIcon(Test.class.getResource("image.png"));
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(true);
frame.setSize(100, 100);
//other stuffs....
}
}
So in this application I'm making, the user clicks on a button, and that button launches a program. This button will have the title of the application and the icon. I just need to know how to get the icon, kind of like this: Windows http://goo.gl/5WjdT
So what I want to know is this:
Is there any REAL way to do this in Java
If so, how would you do it?
Thanks in advance!
Do you have to get the icon associated to the exe file of the application ? If so it is possible in java, take a look at this tutorial, that explain several ways of extracting app icon from an executable binary file from a Java application.
Take a look at this code :
String s = "c:/windows/regedit.exe";
File file = new File(s);
// Get metadata and create an icon
sun.awt.shell.ShellFolder sf =
sun.awt.shell.ShellFolder.getShellFolder(file);
Icon icon = new ImageIcon(sf.getIcon(true));
You can simply use FileSystemView for that purpose:
public static void main(String[] args) {
Icon icon = FileSystemView.getFileSystemView()
.getSystemIcon(new File("C:\\Windows\\regedit.exe"));
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JLabel(icon));
frame.pack();
frame.setVisible(true);
}