Java Jwindow not showing like before

조회 수: 3 (최근 30일)
AbioEngineer
AbioEngineer 2021년 1월 7일
답변: AbioEngineer 2021년 1월 8일
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에서 Call Java from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by