Skip to content

Commit

Permalink
added support for JTabbedPane
Browse files Browse the repository at this point in the history
  • Loading branch information
atarw committed Jun 20, 2018
1 parent 73097a0 commit 0fb07d1
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 60 deletions.
111 changes: 55 additions & 56 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified lib/material-ui-swing.jar
Binary file not shown.
4 changes: 0 additions & 4 deletions src/MaterialUISwingDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.BorderLayout;
Expand Down Expand Up @@ -67,9 +66,6 @@ public static void main (String[] args) {
Color blue = new Color (34, 167, 240);
MaterialUIMovement.add (button, blue, 5, 1000 / 30);

JRadioButton b = new JRadioButton ("test");
content.add (b);

// make everything visible to the world
frame.pack ();
frame.setVisible (true);
Expand Down
3 changes: 3 additions & 0 deletions src/mdlaf/MaterialLookAndFeel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import mdlaf.components.password.MaterialPasswordFieldUI;
import mdlaf.components.radiobutton.MaterialRadioButtonUI;
import mdlaf.components.spinner.MaterialSpinnerUI;
import mdlaf.components.tabbedpane.MaterialTabbedPaneUI;
import mdlaf.components.table.MaterialTableHeaderUI;
import mdlaf.components.table.MaterialTableUI;
import mdlaf.components.textfield.MaterialTextFieldUI;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class MaterialLookAndFeel extends BasicLookAndFeel {
private static final String menuUI = MaterialMenuUI.class.getCanonicalName ();
private static final String checkBoxUI = MaterialCheckBoxUI.class.getCanonicalName ();
private static final String radioButtonUI = MaterialRadioButtonUI.class.getCanonicalName ();
private static final String tabbedPaneUI = MaterialTabbedPaneUI.class.getCanonicalName ();

@Override
public String getName () {
Expand Down Expand Up @@ -82,6 +84,7 @@ protected void initClassDefaults (UIDefaults table) {
table.put ("MenuUI", menuUI);
table.put ("CheckBoxUI", checkBoxUI);
table.put ("RadioButtonUI", radioButtonUI);
table.put ("TabbedPaneUI", tabbedPaneUI);
}

@Override
Expand Down
65 changes: 65 additions & 0 deletions src/mdlaf/components/tabbedpane/MaterialTabbedPaneUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package mdlaf.components.tabbedpane;

import mdlaf.resources.MaterialColors;
import mdlaf.resources.MaterialDrawingUtils;
import mdlaf.resources.MaterialFonts;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JTabbedPane;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class MaterialTabbedPaneUI extends BasicTabbedPaneUI {

public static ComponentUI createUI (JComponent c) {
return new MaterialTabbedPaneUI ();
}

@Override
public void installUI (JComponent c) {
super.installUI (c);

JTabbedPane tabbedPane = (JTabbedPane) c;
tabbedPane.setOpaque (false);
tabbedPane.setFont (MaterialFonts.REGULAR);
tabbedPane.setBackground (Color.WHITE);
tabbedPane.setForeground (Color.BLACK);
tabbedPane.setBorder (BorderFactory.createEmptyBorder ());

darkShadow = null;
shadow = null;
lightHighlight = MaterialColors.LIGHT_GRAY;
}

@Override
public void paint (Graphics g, JComponent c) {
super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c);
}

@Override
protected void paintTabBackground (Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
g.setColor (isSelected ? lightHighlight : tabPane.getBackground ());
g.fillRect (x, y, w, h);
}

@Override
protected void paintTabBorder (Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
g.setColor (Color.LIGHT_GRAY);
g.drawRect (x, y, w, h);
}

@Override
protected void paintFocusIndicator (Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
// do nothing
}

@Override
protected void paintTab (Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) {
// for some reason tabs aren't painted properly by paint()
super.paintTab (MaterialDrawingUtils.getAliasedGraphics (g), tabPlacement, rects, tabIndex, iconRect, textRect);
}
}

0 comments on commit 0fb07d1

Please sign in to comment.