英文:
How to remove red hat icon from top left corner Java Swing
问题
是否有办法从JDialog窗口左上角删除RHEL红帽图标?目的是只保留文本“Activities”。
红帽图标
我已经尝试搜索图像的来源,但没有成功。
您能帮忙吗?
谢谢。
英文:
Is there a way of removing the rhel red hat icon from top left corner in JDialog window ?
Purpose is to have only the text "Activities".
red hat icon
I have tried to search from where is coming that image, but no success.
Can you please help ?
Thanks
答案1
得分: 0
以下是您要翻译的内容:
"The only thing I can think of of hand is the same thing as what was suggested by @user16320675. Create and use a small transparent empty image to replace the default image. This does however leave an icon sized gap between the left edge of the frame and the text. It may be a good idea to try and center the text within the title Bar."
"您可以尝试以下提供的方法。在以下任何代码中阅读评论:"
/**
-
Replaces the Title Bar Icon with a created blank (tranparent) .png image.
-
@param comp (java.awt.Component) Any Component variable name related to
-
the JFrame or JDialog.
*/
public void noFormIcon(java.awt.Component comp) {
// Create an empty .png image
java.awt.image.BufferedImage image =
new java.awt.image.BufferedImage(5, 5, java.awt.image.BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics2D g2d = image.createGraphics();
g2d.setComposite(java.awt.AlphaComposite.Clear);
g2d.fillRect(0, 0, 5, 5);
g2d.dispose();// Apply the created Image to the Component's Parent Window.
java.awt.Window win = javax.swing.SwingUtilities.getWindowAncestor(comp);
if (win != null) {
win.setIconImage(image);
}
}
To use this method you might have something like this:
// Instantiate a JDialog Window:
javax.swing.JDialog dia = new javax.swing.JDialog();
dia.setTitle("Some Dialog Window"); // Set dialog title.
// Set its size:
dia.setSize(300, 200); // Set dialog size.
dia.setAlwaysOnTop(true); // Set 'Always On Top'
dia.setModal(true); // Set dialog to be Modal.
// Dispose of dialog when closed.
dia.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
dia.setLocationRelativeTo(null); // center dialog to Screen
// Instantiate a JLabel and apply a caption:
javax.swing.JLabel label = new javax.swing.JLabel("Some JLabel In Dialog Window");
// Set the Horizontal Alignment for the Caption text to be Center.
label.setHorizontalAlignment(javax.swing.JLabel.CENTER);
// Add the JLabel to the JDialog
dia.add(label);
// Replace the dialog title Bar Icon Image with an empty .png:
noFormIcon(dia);
// Display the dialog.
java.awt.EventQueue.invokeLater(() -> {
dia.setVisible(true);
});
1: https://i.stack.imgur.com/WHhS4.png
英文:
The only thing I can think of of hand is the same thing as what was suggested by @user16320675. Create and use a small transparent empty image to replace the default image. This does however leave an icon sized gap between the left edge of the frame and the text. It may be a good idea to try and center the text within the title Bar.
You can try something like this provided method. Read comments in any of the following code:
/**
* Replaces the Title Bar Icon with a created blank (tranparent) .png image.
*
* @param comp (java.awt.Component) Any Component variable name related to
* the JFrame or JDialog.
*/
public void noFormIcon(java.awt.Component comp) {
// Create an empty .png image
java.awt.image.BufferedImage image =
new java.awt.image.BufferedImage(5, 5, java.awt.image.BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics2D g2d = image.createGraphics();
g2d.setComposite(java.awt.AlphaComposite.Clear);
g2d.fillRect(0, 0, 5, 5);
g2d.dispose();
// Apply the created Image to the Component's Parent Window.
java.awt.Window win = javax.swing.SwingUtilities.getWindowAncestor(comp);
if (win != null) {
win.setIconImage(image);
}
}
To use this method you might have something like this:
// Instantiate a JDialog Window:
javax.swing.JDialog dia = new javax.swing.JDialog();
dia.setTitle("Some Dialog Window"); // Set dialog title.
// Set its size:
dia.setSize(300, 200); // Set dialog size.
dia.setAlwaysOnTop(true); // Set 'Always On Top'
dia.setModal(true); // Set dialog to be Modal.
// Dispose of dialog when closed.
dia.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
dia.setLocationRelativeTo(null); // center dialog to Screen
// Instantiate a JLabel and applpy a caption:
javax.swing.JLabel label = new javax.swing.JLabel("Some JLabel In Dialog Window");
// Set the Horizontal Alignment for the Caption text to be Center.
label.setHorizontalAlignment(javax.swing.JLabel.CENTER);
// Add the JLabel to the JDialog
dia.add(label);
// Replace the dialog title Bar Icon Image with an empty .png:
noFormIcon(dia);
// Display the dialog.
java.awt.EventQueue.invokeLater(() -> {
dia.setVisible(true);
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论