How to set the default icon for all Java Swing windows?
How to set the default icon for all Java Swing windows?
Otherwise i have to set icons for every frame i created.
What's your suggestions?
Simple hackings are also accepted.
many thx
Update: Best if the method you suggested can leave existing frame-creation codes untouched. thx
java swing icons
add a comment |
How to set the default icon for all Java Swing windows?
Otherwise i have to set icons for every frame i created.
What's your suggestions?
Simple hackings are also accepted.
many thx
Update: Best if the method you suggested can leave existing frame-creation codes untouched. thx
java swing icons
Applications should have a single JFrame. Then you use JDialogs for other child windows of the application. So as krock suggestion you only need to change the icon in a single place when the JFrame is first created.
– camickr
Jul 6 '10 at 5:21
add a comment |
How to set the default icon for all Java Swing windows?
Otherwise i have to set icons for every frame i created.
What's your suggestions?
Simple hackings are also accepted.
many thx
Update: Best if the method you suggested can leave existing frame-creation codes untouched. thx
java swing icons
How to set the default icon for all Java Swing windows?
Otherwise i have to set icons for every frame i created.
What's your suggestions?
Simple hackings are also accepted.
many thx
Update: Best if the method you suggested can leave existing frame-creation codes untouched. thx
java swing icons
java swing icons
edited Jul 6 '10 at 3:38
Defd
asked Jul 6 '10 at 3:02
DefdDefd
390114
390114
Applications should have a single JFrame. Then you use JDialogs for other child windows of the application. So as krock suggestion you only need to change the icon in a single place when the JFrame is first created.
– camickr
Jul 6 '10 at 5:21
add a comment |
Applications should have a single JFrame. Then you use JDialogs for other child windows of the application. So as krock suggestion you only need to change the icon in a single place when the JFrame is first created.
– camickr
Jul 6 '10 at 5:21
Applications should have a single JFrame. Then you use JDialogs for other child windows of the application. So as krock suggestion you only need to change the icon in a single place when the JFrame is first created.
– camickr
Jul 6 '10 at 5:21
Applications should have a single JFrame. Then you use JDialogs for other child windows of the application. So as krock suggestion you only need to change the icon in a single place when the JFrame is first created.
– camickr
Jul 6 '10 at 5:21
add a comment |
2 Answers
2
active
oldest
votes
Create an Abstact class that extends JFrame
In the constructor set your icon.
create child class that extends your new Abstract Class
and call super
in your constructor
public abstract class MainFrame extends JFrame {
protected MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class ChildFrame extends MainFrame {
public ChildFrame() {
super();
}
}
You can also just create object from your new class
public class MainFrame extends JFrame {
public MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class Frame {
private MainFrame mainframe = new MainFrame();
public Frame() {
super();
}
}
1
+1 Also I believe all JDialogs inherit the icon from their parent window, so just need to worry about the JFrames/JWindows.
– krock
Jul 6 '10 at 3:10
That's still an alternative method to set icon for every frame created. The biggest drawback is that it's not friendly with existing codes.
– Defd
Jul 6 '10 at 3:37
Also it doesn't work well with third party libraries spawning frames.
– Emmanuel Bourg
Feb 16 '12 at 16:34
add a comment |
To make windows icons changes globally without changing old code I am using this code snippet
public static void fixWindowsIcons(final List<Image> iconImages) {
PropertyChangeListener l = new PropertyChangeListener() {
private Window prevActiveWindow;
@Override
public void propertyChange(PropertyChangeEvent evt) {
final Window o = KeyboardFocusManager.getCurrentKeyboardFocusManager()
.getActiveWindow();
if (o != null && prevActiveWindow != o) {
prevActiveWindow = o;
List<Image> windowIcons = o.getIconImages();
if (windowIcons == null || windowIcons.size() == 0) {
o.setIconImages(iconImages);
}
}
}
};
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("activeWindow", l); //$NON-NLS-1$
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3183259%2fhow-to-set-the-default-icon-for-all-java-swing-windows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Create an Abstact class that extends JFrame
In the constructor set your icon.
create child class that extends your new Abstract Class
and call super
in your constructor
public abstract class MainFrame extends JFrame {
protected MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class ChildFrame extends MainFrame {
public ChildFrame() {
super();
}
}
You can also just create object from your new class
public class MainFrame extends JFrame {
public MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class Frame {
private MainFrame mainframe = new MainFrame();
public Frame() {
super();
}
}
1
+1 Also I believe all JDialogs inherit the icon from their parent window, so just need to worry about the JFrames/JWindows.
– krock
Jul 6 '10 at 3:10
That's still an alternative method to set icon for every frame created. The biggest drawback is that it's not friendly with existing codes.
– Defd
Jul 6 '10 at 3:37
Also it doesn't work well with third party libraries spawning frames.
– Emmanuel Bourg
Feb 16 '12 at 16:34
add a comment |
Create an Abstact class that extends JFrame
In the constructor set your icon.
create child class that extends your new Abstract Class
and call super
in your constructor
public abstract class MainFrame extends JFrame {
protected MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class ChildFrame extends MainFrame {
public ChildFrame() {
super();
}
}
You can also just create object from your new class
public class MainFrame extends JFrame {
public MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class Frame {
private MainFrame mainframe = new MainFrame();
public Frame() {
super();
}
}
1
+1 Also I believe all JDialogs inherit the icon from their parent window, so just need to worry about the JFrames/JWindows.
– krock
Jul 6 '10 at 3:10
That's still an alternative method to set icon for every frame created. The biggest drawback is that it's not friendly with existing codes.
– Defd
Jul 6 '10 at 3:37
Also it doesn't work well with third party libraries spawning frames.
– Emmanuel Bourg
Feb 16 '12 at 16:34
add a comment |
Create an Abstact class that extends JFrame
In the constructor set your icon.
create child class that extends your new Abstract Class
and call super
in your constructor
public abstract class MainFrame extends JFrame {
protected MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class ChildFrame extends MainFrame {
public ChildFrame() {
super();
}
}
You can also just create object from your new class
public class MainFrame extends JFrame {
public MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class Frame {
private MainFrame mainframe = new MainFrame();
public Frame() {
super();
}
}
Create an Abstact class that extends JFrame
In the constructor set your icon.
create child class that extends your new Abstract Class
and call super
in your constructor
public abstract class MainFrame extends JFrame {
protected MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class ChildFrame extends MainFrame {
public ChildFrame() {
super();
}
}
You can also just create object from your new class
public class MainFrame extends JFrame {
public MainFrame() {
this.setIconImage(null); // Put your own image instead of null
}
}
public class Frame {
private MainFrame mainframe = new MainFrame();
public Frame() {
super();
}
}
edited Jul 6 '10 at 3:28
answered Jul 6 '10 at 3:06
Michael B.Michael B.
3,33311731
3,33311731
1
+1 Also I believe all JDialogs inherit the icon from their parent window, so just need to worry about the JFrames/JWindows.
– krock
Jul 6 '10 at 3:10
That's still an alternative method to set icon for every frame created. The biggest drawback is that it's not friendly with existing codes.
– Defd
Jul 6 '10 at 3:37
Also it doesn't work well with third party libraries spawning frames.
– Emmanuel Bourg
Feb 16 '12 at 16:34
add a comment |
1
+1 Also I believe all JDialogs inherit the icon from their parent window, so just need to worry about the JFrames/JWindows.
– krock
Jul 6 '10 at 3:10
That's still an alternative method to set icon for every frame created. The biggest drawback is that it's not friendly with existing codes.
– Defd
Jul 6 '10 at 3:37
Also it doesn't work well with third party libraries spawning frames.
– Emmanuel Bourg
Feb 16 '12 at 16:34
1
1
+1 Also I believe all JDialogs inherit the icon from their parent window, so just need to worry about the JFrames/JWindows.
– krock
Jul 6 '10 at 3:10
+1 Also I believe all JDialogs inherit the icon from their parent window, so just need to worry about the JFrames/JWindows.
– krock
Jul 6 '10 at 3:10
That's still an alternative method to set icon for every frame created. The biggest drawback is that it's not friendly with existing codes.
– Defd
Jul 6 '10 at 3:37
That's still an alternative method to set icon for every frame created. The biggest drawback is that it's not friendly with existing codes.
– Defd
Jul 6 '10 at 3:37
Also it doesn't work well with third party libraries spawning frames.
– Emmanuel Bourg
Feb 16 '12 at 16:34
Also it doesn't work well with third party libraries spawning frames.
– Emmanuel Bourg
Feb 16 '12 at 16:34
add a comment |
To make windows icons changes globally without changing old code I am using this code snippet
public static void fixWindowsIcons(final List<Image> iconImages) {
PropertyChangeListener l = new PropertyChangeListener() {
private Window prevActiveWindow;
@Override
public void propertyChange(PropertyChangeEvent evt) {
final Window o = KeyboardFocusManager.getCurrentKeyboardFocusManager()
.getActiveWindow();
if (o != null && prevActiveWindow != o) {
prevActiveWindow = o;
List<Image> windowIcons = o.getIconImages();
if (windowIcons == null || windowIcons.size() == 0) {
o.setIconImages(iconImages);
}
}
}
};
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("activeWindow", l); //$NON-NLS-1$
}
add a comment |
To make windows icons changes globally without changing old code I am using this code snippet
public static void fixWindowsIcons(final List<Image> iconImages) {
PropertyChangeListener l = new PropertyChangeListener() {
private Window prevActiveWindow;
@Override
public void propertyChange(PropertyChangeEvent evt) {
final Window o = KeyboardFocusManager.getCurrentKeyboardFocusManager()
.getActiveWindow();
if (o != null && prevActiveWindow != o) {
prevActiveWindow = o;
List<Image> windowIcons = o.getIconImages();
if (windowIcons == null || windowIcons.size() == 0) {
o.setIconImages(iconImages);
}
}
}
};
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("activeWindow", l); //$NON-NLS-1$
}
add a comment |
To make windows icons changes globally without changing old code I am using this code snippet
public static void fixWindowsIcons(final List<Image> iconImages) {
PropertyChangeListener l = new PropertyChangeListener() {
private Window prevActiveWindow;
@Override
public void propertyChange(PropertyChangeEvent evt) {
final Window o = KeyboardFocusManager.getCurrentKeyboardFocusManager()
.getActiveWindow();
if (o != null && prevActiveWindow != o) {
prevActiveWindow = o;
List<Image> windowIcons = o.getIconImages();
if (windowIcons == null || windowIcons.size() == 0) {
o.setIconImages(iconImages);
}
}
}
};
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("activeWindow", l); //$NON-NLS-1$
}
To make windows icons changes globally without changing old code I am using this code snippet
public static void fixWindowsIcons(final List<Image> iconImages) {
PropertyChangeListener l = new PropertyChangeListener() {
private Window prevActiveWindow;
@Override
public void propertyChange(PropertyChangeEvent evt) {
final Window o = KeyboardFocusManager.getCurrentKeyboardFocusManager()
.getActiveWindow();
if (o != null && prevActiveWindow != o) {
prevActiveWindow = o;
List<Image> windowIcons = o.getIconImages();
if (windowIcons == null || windowIcons.size() == 0) {
o.setIconImages(iconImages);
}
}
}
};
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("activeWindow", l); //$NON-NLS-1$
}
answered Nov 24 '18 at 15:58
peslyspeslys
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3183259%2fhow-to-set-the-default-icon-for-all-java-swing-windows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Applications should have a single JFrame. Then you use JDialogs for other child windows of the application. So as krock suggestion you only need to change the icon in a single place when the JFrame is first created.
– camickr
Jul 6 '10 at 5:21