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

How to add a Navigation Tab Activity to a Tabbed Activity
android studio Make a textView below an imageview visible if imageview has no image
Make card game GUI in Java
Travis-CI Java build project with own dependencies
Database configuration with Spring boot needs to be in web to work properly
Android studio, programm just change some phone settings and go off
How to safely close a socket in Java? What am I doing wrong since I am getting an exception?
FileNotFoundException in Spring
Create keystore from rsa file
How to use parameter as a variable in another method
Selenium java chrome driver, get last download name
Netbeans: how do i write a txt file fomr one jframe and display it in a jtable in another frame?
How to change image when checkbox checked
Java - 2d Array not filling when transferring info from file
Is it possible to forward 2 requests from 2 different servlets to 1 jsp?
How to check if there are any notification in android?

Categories

HOME
compiler-construction
osgi
image
listview
keycloak
urbancode
hashmap
office365api
cplex
react-router
webstorm
q
sqlite-net-extensions
yarn
jxls
binary-tree
fsm
kibana-4
offline
numeral.js
modelica
ups
carthage
systemc
progressive-web-apps
reactive-cocoa
samoa
firefox-webextensions
amazonsellercentral
physics-engine
firebase-crash-reporting
microsoft-sync-framework
bootstrap-material-design
filezilla
assistant
kendo-datasource
objectanimator
avcapturesession
android-kernel
google-api-nodejs-client
mpmediaquery
multilingual
reportbuilder
graphenedb
quadratic-programming
appcompat
winscp-net
boost-preprocessor
sqlbulkcopy
memory-alignment
nbconvert
redundancy
or-tools
url-pattern
google-feed-api
android-textview
azure-virtual-network
xml-attribute
gridview-sorting
hover-over
goose
xpath-1.0
lemon
security-testing
npapi
csquery
java.util.concurrent
heisenbug
android-2.2-froyo
industrial
page-layout
xsockets.net
commoncrypto
ocunit
itmstransporter
pysimplesoap
windows-phone-7.1.1
adk
appender
castle-monorail
iweb
data-driven
temporal-database
ajax-forms

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