Skip to content

Instantly share code, notes, and snippets.

@ricardojlrufino
Last active May 19, 2020 18:20
Show Gist options
  • Save ricardojlrufino/b65c41219ec11e429694e6daab36ee4e to your computer and use it in GitHub Desktop.
Save ricardojlrufino/b65c41219ec11e429694e6daab36ee4e to your computer and use it in GitHub Desktop.
package layout.tabs;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
import com.jidesoft.plaf.vsnet.VsnetJideTabbedPaneUI;
public class CustomVsnetJideTabbedPaneUI extends VsnetJideTabbedPaneUI {
protected void installDefaults() {
super.installDefaults();
// _tabRectPadding = 20;
// _tabRectPadding = 20;
// _textPadding=400;
// _buttonSize= 400;
// _buttonMargin= 400;
// _fitStyleFirstTabMargin = 400;
/// _showCloseButtonOnTab
}
@Override
public void paintBackground( Graphics g , Component c ) {
int width = c.getWidth();
int height = c.getHeight();
g.setColor(new Color(23, 161, 165));
g.fillRect(0, 0, width, height);
}
@Override
protected void paintTabAreaBackground( Graphics g , Rectangle rect , int tabPlacement ) {
g.setColor(new Color(23, 161, 165));
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
//
// @Override
// protected void paintButtonTabBackground( Graphics g , int tabPlacement , int tabIndex , int x , int y , int w , int h , boolean isSelected ) {
// g.setColor(Color.YELLOW);
// g.fillRect(x, y, w, h);
// }
//
// @Override
// protected void paintVsnetTabBackground( Graphics g , int tabPlacement , int tabIndex , int x , int y , int w , int h , boolean isSelected ) {
// g.setColor(Color.YELLOW);
// g.fillRect(x, y, w, h);
// }
@Override
protected void paintTabBackground( Graphics g , int tabPlacement , int tabIndex , int x , int y , int w , int h , boolean isSelected ) {
g.setColor(Color.YELLOW);
g.fillRect(x, y, w, h);
}
@Override
protected void paintFlatTabBorder( Graphics g , int tabPlacement , int tabIndex , int x , int y , int w , int h , boolean isSelected ) {
// TODO Auto-generated method stub
// super.paintFlatTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
// super.paintFlatTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
}
@Override
protected void paintText( Graphics g , int tabPlacement , Font font , FontMetrics metrics , int tabIndex , String title , Rectangle textRect , boolean isSelected ) {
// TODO Auto-generated method stub
super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
}
@Override
protected void paintBoxTabBorder( Graphics g , int tabPlacement , int tabIndex , int x , int y , int w , int h , boolean isSelected ) {
// super.paintBoxTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
}
@Override
protected void paintContentBorderTopEdge( Graphics g , int tabPlacement , int selectedIndex , int x , int y , int w , int h ) {
// TODO Auto-generated method stub
// super.paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);
}
@Override
protected void paintContentBorderBottomEdge( Graphics g , int tabPlacement , int selectedIndex , int x , int y , int w , int h ) {
// TODO Auto-generated method stub
// super.paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
}
@Override
protected void paintContentBorderLeftEdge( Graphics g , int tabPlacement , int selectedIndex , int x , int y , int w , int h ) {
// TODO Auto-generated method stub
// super.paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);
}
@Override
protected void paintContentBorderRightEdge( Graphics g , int tabPlacement , int selectedIndex , int x , int y , int w , int h ) {
// TODO Auto-generated method stub
// super.paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
}
@Override
protected void paintContentBorder( Graphics g , int tabPlacement , int selectedIndex ) {
// TODO Auto-generated method stub
// super.paintContentBorder(g, tabPlacement, selectedIndex);
}
@Override
protected int calculateTabHeight( int tabPlacement , int tabIndex , FontMetrics metrics ) {
// TODO Auto-generated method stub
return 50;
}
@Override
protected int calculateTabWidth( int tabPlacement , int tabIndex , FontMetrics metrics ) {
return 100;
}
// @Override
// protected int calculateTabAreaHeight( int tabPlacement , int horizRunCount , int maxTabHeight ) {
// // TODO Auto-generated method stub
// return 120;
// }
}
package layout.tabs;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.UIDefaults;
import javax.swing.plaf.UIResource;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.plaf.LookAndFeelFactory.UIDefaultsCustomizer;
import com.jidesoft.swing.JideButton;
import com.jidesoft.swing.JideTabbedPane;
public class JideTabbedPaneTest extends JPanel {
private static final long serialVersionUID = 1L;
public JideTabbedPaneTest() {
// Insets insets = UIManager.getInsets("TabbedPane.contentBorderInsets");
// insets.top = -1;
// UIManager.put("TabbedPane.contentBorderInsets", insets);
LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
LookAndFeelFactory.addUIDefaultsCustomizer(new UIDefaultsCustomizer() {
@Override
public void customize( UIDefaults defaults ) {
defaults.put("JideTabbedPane.textPadding", 60);
defaults.put("JideTabbedPane.fitStyleFirstTabMargin", 60);
}
});
// try {
// UIManager.setLookAndFeel( new FlatLightLaf() );
// } catch( Exception ex ) {
// System.err.println( "Failed to initialize LaF" );
// };
setLayout(new BorderLayout());
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
JideTabbedPane tb = new JideTabbedPane();
// tb.setTabShape(JideTabbedPane.SHAPE_VSNET);
// tb.setColorTheme(JideTabbedPane.COLOR_THEME_VSNET);
tb.setTabShape(JideTabbedPane.SHAPE_FLAT);
tb.setColorTheme(JideTabbedPane.COLOR_THEME_OFFICE2003);
// tb.setShowCloseButton(true);
tb.setTabEditingAllowed(true);
tb.setContentBorderInsets(new Insets(0, 0, 0, 0));
tb.setTabAreaInsets(new Insets(20, 5, 0, 0));
tb.setTabTrailingComponent(new UpdateButton());
tb.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
tb.add("Tab1", new FakeComponent());
tb.add("Tab2", new FakeComponent());
tb.add("Tab3", new FakeComponent());
tb.add("Tab4", new FakeComponent());
tb.add("Tab5", new FakeComponent());
tb.add("Tab5", new FakeComponent());
tb.add("Tab5", new FakeComponent());;
tb.add("Tab5", new FakeComponent());
jp.add(tb, BorderLayout.NORTH);
jp.add(new JTextArea("...."), BorderLayout.CENTER);
tb.setUI(new CustomVsnetJideTabbedPaneUI());
add(jp, BorderLayout.CENTER);
// tb.setEnabledAt(1, false);
tb.setEnabledAt(3, false);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new JideTabbedPaneTest());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 200);
frame.setVisible(true);
}
class UpdateButton extends JideButton implements UIResource {
public UpdateButton() {
super("ADD");
setButtonStyle(JideButton.FLAT_STYLE);
setAlignmentY(30);
setMargin(new Insets(0, 20, 20, 20));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// saveAction.setPaymentForm(PaymentCompositePanel.this);
// PaymentCompositePanel.this.saveAction.actionPerformed(null);
}
});
}
}
private static class FakeComponent extends JComponent{
@Override
public Dimension getSize() {
Dimension size = super.getSize();
size.height = 0;
return size;
}
@Override
public Dimension getPreferredSize() {
Dimension size =super.getPreferredSize();
size.height = 0;
return size;
}
@Override
public void paint( Graphics g ) {
int width = getWidth();
int height = getHeight();
g.setColor(Color.YELLOW);
g.fillRect(0, 0, width, height);
}
}
}
@ricardojlrufino
Copy link
Author

ricardojlrufino commented May 18, 2020

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>testeswing2</groupId>
    <artifactId>testeswing2</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.jidesoft/jide-oss -->
        <dependency>
            <groupId>com.jidesoft</groupId>
            <artifactId>jide-oss</artifactId>
            <version>3.6.18</version>
        </dependency>

    </dependencies>
</project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment