Java Jwindow not showing like before

2 次查看(过去 30 天)
The JWindow object is not able to show anymore. I'm using a transparent jwindow to house a gif as a loading screen for my app, but the window does not show. Manually running the code in the command window of r2020b isn't working like it did for r2019a. Can anyone please run this below code with an image you have laying around and see if you can get it to display? I just updated to r2020b and now it doesn't work for me.
win = javax.swing.JWindow;
win.setBackground(java.awt.Color(0,0,0,0));
html=strcat('<html><img src="file:./',YOUR IMAGE HERE,'"/></html>');
label = javax.swing.JLabel(html);
win.getContentPane.add(label);
win.setAlwaysOnTop(true);
win.pack;
%% set the splash image to the center of the screen
screenSize = win.getToolkit.getScreenSize;
screenHeight = screenSize.height;
screenWidth = screenSize.width;
% set Location
win.setLocation((screenWidth-500)/2,(screenHeight-500)/2);
win.show

采纳的回答

AbioEngineer
AbioEngineer 2021-1-8
Sorry to answer my own question. Just thought I'd share that JLabel no longer scales itself to fit the image dimensions. In short, just replace the html line with
html=sprintf('<html><img src="file:./%s" width="%d" height="%d">', filename, imageWidth, imageHeight);
Obviously, replace these variable names or assign them values. You can also use java's bufferedimage class with the method getWidth() and getHeight() to find these dimensions

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by