java


Why images doesn't resize when I am trying to enlarge the window [duplicate]


This question already has an answer here:
I need to make my JPanel resize dynamically as new components are being added to it
1 answer
How to fit Image size to JFrame Size?
6 answers
I tried to make slideshow - images should be showed as the background of the window, so when I am large the window it should be resized. At the start images have right original size, but when I am enlarging the window, images doesn't change their size, there still have original size.
I'd like to get it using class which extends JFrame, beucase I made attempt using JPanel - then images was resizeable, but each next image didn't adjust to the original size of the image (e.g. if the image have size 400x500px then frame should have that size but when I enlarge the window manually, it should become larger).
Could anyone tell me why I can't resize that images?
My window in situation when I changed its' size manually
public class Browser extends JFrame
{
private JLabel label;
private final File dir;
private int period, size;
private ImageIcon img;
private boolean end = false;
private int n = 0;
private File[] files;
private String m1 = "Koniec prezentacji", m2 = "Brak obrazka";
public Browser(String[] args)
{
panel = new JPanel();
setLayout(new BorderLayout());
dir = new File(args[0]);
period = Integer.parseInt(args[1]) * 1000;
size = Integer.parseInt(args[2]);
files = dir.listFiles();
Timer timer = new Timer(period, new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (n < files.length)
{
setImage(files[n].getPath());
}
else
{
end = true;
JLabel l = new JLabel(m1, SwingConstants.CENTER);
setSize(200, 200);
setContentPane(l);
((Timer)e.getSource()).stop();
}
n++;
}
});
timer.start();
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(true);
setVisible(true);
}
public void setImage(String imgFileName)
{
img = new ImageIcon(imgFileName);
int w = img.getIconWidth();
int h = img.getIconHeight();
label = new JLabel(img);
if (w != -1 && w != 0 && h != -1 && h != 0)
{
setContentPane(label);
setSize(w, h);
}
else
{
JLabel l = new JLabel(m2, SwingConstants.CENTER);
setSize(200, 200);
setContentPane(l);
}
}
}

Related Links

tomcat changes 404 status into 403 for http delete
Spring Json property mapping an array of Strings to a field in an array of Objects
What is the difference between Scheduler and Timer in GWT?
Scheduling Threads and Synchronized Methods
Maven executable jar packaging vs Maven exec with Jackson not working
Can't load data to TableView
Most efficient way to sort by multiple fields in Java
Is it possible to map Spring components through annotations using enums?
WildFly command inside domain.sh
In Java when one methods in an object is 'synchronized' are all methods 'synchronized'?
How to clamp a value from 0 to infinite to a value from 0 to 1?
Read file from SVN over https using svnkit
How to change programmmatically an array in PageAdapter class
java get only one prime number randomly
Execute code after each period of time, JAVA
Invoke prepareRenderer of JTable Swing

Categories

HOME
maven
testing
netbeans
minimum-spanning-tree
rsyslog
amortized-analysis
sharepoint-designer
retrofit
izpack
nstableview
apache-cayenne
task
pythonanywhere
firefox-webextensions
autoconf
ehcache
wkwebview
crosstab
traffic
xacml
bluestacks
junit5
semantic-versioning
geopositioning
host
web-mining
ansible-playbook
squib
gzipstream
grid.mvc
jvm-languages
fault
jedis
jquery-validate
pnotify
datastax-startup
git-diff
nstextview
drupal-6
font-size
dtexec
python-cryptography
mako
titanium-android
deadbolt-2
nxt
bonobo
multi-level
google-web-starter-kit
bstr
lttng
pagedlist
skype4py
natvis
intel-fortran
ora-00900
atk4
myo
method-parameters
sankey-diagram
processmodel
nsight
truevault
javax.mail
eol
valuechangelistener
undefined-reference
industrial
multiprocessor
blending
buster.js
django-nonrel
sqlperformance
pygit2
limejs
enterprisedb
android-hardware
wsdl-2.0
tinn-r
cisco-jtapi
first-responder
javaspaces
ticoredatasync
asyncfileupload
pydot
yetanotherforum
asp.net-mvc-areas
gallio
revisions
modelstate
adrotator
phonon

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App