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