Skip to content

Commit

Permalink
InternalFrame: use default icon in internal frames (issue #122)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Jul 6, 2020
1 parent 9e731cb commit f22862b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ FlatLaf Change Log
- Hide focus indicator when window is inactive.
- Custom window decorations: Improved/fixed window border color in dark themes.
- Custom window decorations: Hide window border if window is maximized.
- Custom window decorations: Center title if menu bar is embedded.
- InternalFrame: Use default icon in internal frames. (issue #122)


## 0.37
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import com.formdev.flatlaf.util.ScaledImageIcon;
import com.formdev.flatlaf.util.UIScale;

/**
Expand Down Expand Up @@ -103,14 +104,16 @@ protected void addSubComponents() {
add( buttonPanel, BorderLayout.LINE_END );
}

private void updateFrameIcon() {
protected void updateFrameIcon() {
Icon frameIcon = frame.getFrameIcon();
if( frameIcon == UIManager.getIcon( "InternalFrame.icon" ) )
if( frameIcon != null && (frameIcon.getIconWidth() == 0 || frameIcon.getIconHeight() == 0) )
frameIcon = null;
else if( frameIcon instanceof ImageIcon )
frameIcon = new ScaledImageIcon( (ImageIcon) frameIcon );
titleLabel.setIcon( frameIcon );
}

private void updateColors() {
protected void updateColors() {
Color background = FlatUIUtils.nonUIResource( frame.isSelected() ? selectedTitleColor : notSelectedTitleColor );
Color foreground = FlatUIUtils.nonUIResource( frame.isSelected() ? selectedTextColor : notSelectedTextColor );

Expand All @@ -123,7 +126,7 @@ private void updateColors() {
closeButton.setForeground( foreground );
}

private void updateButtonsVisibility() {
protected void updateButtonsVisibility() {
iconButton.setVisible( frame.isIconifiable() );
maxButton.setVisible( frame.isMaximizable() );
closeButton.setVisible( frame.isClosable() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.awt.*;
import java.beans.PropertyVetoException;
import javax.swing.*;
import com.formdev.flatlaf.extras.TriStateCheckBox;
import com.formdev.flatlaf.icons.FlatFileViewFloppyDriveIcon;
import com.formdev.flatlaf.util.UIScale;
import net.miginfocom.swing.*;
Expand Down Expand Up @@ -50,8 +51,10 @@ private void createInternalFrame() {
maximizableCheckBox.isSelected(),
iconifiableCheckBox.isSelected() );

if( iconCheckBox.isSelected() )
if( iconCheckBox.getState() == TriStateCheckBox.State.SELECTED )
internalFrame.setFrameIcon( new FlatFileViewFloppyDriveIcon() );
else if( iconCheckBox.getState() == TriStateCheckBox.State.UNSELECTED )
internalFrame.setFrameIcon( null );

if( menuBarCheckBox.isSelected() ) {
JMenuBar menuBar = new JMenuBar();
Expand Down Expand Up @@ -100,7 +103,7 @@ private void initComponents() {
closableCheckBox = new JCheckBox();
iconifiableCheckBox = new JCheckBox();
maximizableCheckBox = new JCheckBox();
iconCheckBox = new JCheckBox();
iconCheckBox = new TriStateCheckBox();
menuBarCheckBox = new JCheckBox();
titleLabel = new JLabel();
titleField = new JTextField();
Expand Down Expand Up @@ -192,7 +195,7 @@ private void initComponents() {
private JCheckBox closableCheckBox;
private JCheckBox iconifiableCheckBox;
private JCheckBox maximizableCheckBox;
private JCheckBox iconCheckBox;
private TriStateCheckBox iconCheckBox;
private JCheckBox menuBarCheckBox;
private JLabel titleLabel;
private JTextField titleField;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8"
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"

new FormModel {
contentType: "form/swing"
Expand Down Expand Up @@ -50,7 +50,7 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 1,alignx left,growx 0"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
add( new FormComponent( "com.formdev.flatlaf.extras.TriStateCheckBox" ) {
name: "iconCheckBox"
"text": "Frame icon"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
Expand Down

0 comments on commit f22862b

Please sign in to comment.