mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Demo: save/restore last active tab
This commit is contained in:
@@ -20,7 +20,6 @@ import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.prefs.Preferences;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
|
||||
@@ -132,7 +131,7 @@ class ControlBar
|
||||
if( newLaf.className.equals( UIManager.getLookAndFeel().getClass().getName() ) )
|
||||
return;
|
||||
|
||||
Preferences.userRoot().node( FlatLafDemo.PREFS_ROOT_PATH ).put( FlatLafDemo.KEY_LAF, newLaf.className );
|
||||
FlatLafDemo.prefs.put( FlatLafDemo.KEY_LAF, newLaf.className );
|
||||
|
||||
EventQueue.invokeLater( () -> {
|
||||
try {
|
||||
|
||||
@@ -27,8 +27,17 @@ class DemoFrame
|
||||
extends JFrame
|
||||
{
|
||||
DemoFrame() {
|
||||
int tabIndex = FlatLafDemo.prefs.getInt( FlatLafDemo.KEY_TAB, 0 );
|
||||
|
||||
initComponents();
|
||||
controlBar.initialize( this, tabbedPane );
|
||||
|
||||
if( tabIndex >= 0 && tabIndex < tabbedPane.getTabCount() && tabIndex != tabbedPane.getSelectedIndex() )
|
||||
tabbedPane.setSelectedIndex( tabIndex );
|
||||
}
|
||||
|
||||
private void selectedTabChanged() {
|
||||
FlatLafDemo.prefs.putInt( FlatLafDemo.KEY_TAB, tabbedPane.getSelectedIndex() );
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
@@ -60,6 +69,7 @@ class DemoFrame
|
||||
|
||||
//======== tabbedPane ========
|
||||
{
|
||||
tabbedPane.addChangeListener(e -> selectedTabChanged());
|
||||
tabbedPane.addTab("Basic Components", basicComponentsPanel);
|
||||
tabbedPane.addTab("More Components", moreComponentsPanel);
|
||||
tabbedPane.addTab("Data Components", dataComponentsPanel);
|
||||
|
||||
@@ -23,6 +23,7 @@ new FormModel {
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "javax.swing.event.ChangeListener", "stateChanged", "selectedTabChanged", false ) )
|
||||
add( new FormComponent( "com.formdev.flatlaf.demo.BasicComponentsPanel" ) {
|
||||
name: "basicComponentsPanel"
|
||||
}, new FormLayoutConstraints( null ) {
|
||||
|
||||
@@ -27,15 +27,19 @@ public class FlatLafDemo
|
||||
{
|
||||
static final String PREFS_ROOT_PATH = "/flatlaf-demo";
|
||||
static final String KEY_LAF = "laf";
|
||||
static final String KEY_TAB = "tab";
|
||||
|
||||
static Preferences prefs;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
prefs = Preferences.userRoot().node( PREFS_ROOT_PATH );
|
||||
|
||||
// set look and feel
|
||||
try {
|
||||
if( args.length > 0 )
|
||||
UIManager.setLookAndFeel( args[0] );
|
||||
else {
|
||||
String lafClassName = Preferences.userRoot().node( PREFS_ROOT_PATH )
|
||||
.get( KEY_LAF, FlatLightLaf.class.getName() );
|
||||
String lafClassName = prefs.get( KEY_LAF, FlatLightLaf.class.getName() );
|
||||
UIManager.setLookAndFeel( lafClassName );
|
||||
}
|
||||
} catch( Exception ex ) {
|
||||
|
||||
Reference in New Issue
Block a user