mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
OptionPane implementation
This commit is contained in:
@@ -39,6 +39,7 @@ import javax.swing.plaf.basic.BasicLookAndFeel;
|
||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||
import com.formdev.flatlaf.ui.FlatEmptyBorder;
|
||||
import com.formdev.flatlaf.ui.FlatLineBorder;
|
||||
import com.formdev.flatlaf.util.ScaledNumber;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
|
||||
/**
|
||||
@@ -254,6 +255,11 @@ public abstract class FlatLaf
|
||||
if( key.endsWith( "Size" ) && !key.equals( "SplitPane.dividerSize" ))
|
||||
return parseSize( value );
|
||||
|
||||
// scaled number
|
||||
ScaledNumber scaledNumber = parseScaledNumber( key, value );
|
||||
if( scaledNumber != null )
|
||||
return scaledNumber;
|
||||
|
||||
// width, height
|
||||
if( key.endsWith( "Width" ) || key.endsWith( "Height" ) )
|
||||
return parseInteger( value, true );
|
||||
@@ -359,6 +365,18 @@ public abstract class FlatLaf
|
||||
return null;
|
||||
}
|
||||
|
||||
private ScaledNumber parseScaledNumber( String key, String value ) {
|
||||
if( !key.equals( "OptionPane.buttonMinimumWidth" ) )
|
||||
return null; // not supported
|
||||
|
||||
try {
|
||||
return new ScaledNumber( Integer.parseInt( value ) );
|
||||
} catch( NumberFormatException ex ) {
|
||||
System.err.println( "invalid integer '" + value + "'" );
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> split( String str, char delim ) {
|
||||
ArrayList<String> strs = new ArrayList<>();
|
||||
int delimIndex = str.indexOf( delim );
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright 2019 FormDev Software GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicOptionPaneUI;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
/**
|
||||
* Provides the Flat LaF UI delegate for {@link javax.swing.JOptionPane}.
|
||||
*
|
||||
* @uiDefault OptionPane.border Border
|
||||
* @uiDefault OptionPane.messageAreaBorder Border
|
||||
* @uiDefault OptionPane.buttonAreaBorder Border
|
||||
* @uiDefault OptionPane.messageForeground Color
|
||||
* @uiDefault OptionPane.messageFont Font
|
||||
* @uiDefault OptionPane.buttonFont Font
|
||||
*
|
||||
* @uiDefault OptionPane.minimumSize Dimension
|
||||
* @uiDefault OptionPane.maxCharactersPerLine int
|
||||
* @uiDefault OptionPane.iconMessageGap int
|
||||
* @uiDefault OptionPane.messagePadding int
|
||||
* @uiDefault OptionPane.buttonPadding int
|
||||
* @uiDefault OptionPane.buttonMinimumWidth int -1=disabled
|
||||
* @uiDefault OptionPane.sameSizeButtons boolean if true, gives all buttons same size
|
||||
* @uiDefault OptionPane.setButtonMargin boolean if true, invokes button.setMargin(2,4,2,4)
|
||||
* @uiDefault OptionPane.buttonOrientation int 0=center, 2=left, 4=right
|
||||
* @uiDefault OptionPane.isYesLast boolean reverse button order if true
|
||||
*
|
||||
* @uiDefault OptionPane.errorIcon Icon
|
||||
* @uiDefault OptionPane.informationIcon Icon
|
||||
* @uiDefault OptionPane.questionIcon Icon
|
||||
* @uiDefault OptionPane.warningIcon Icon
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatOptionPaneUI
|
||||
extends BasicOptionPaneUI
|
||||
{
|
||||
protected int iconMessageGap;
|
||||
protected int messagePadding;
|
||||
protected int maxCharactersPerLine;
|
||||
private int focusWidth;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
return new FlatOptionPaneUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
iconMessageGap = UIManager.getInt( "OptionPane.iconMessageGap" );
|
||||
messagePadding = UIManager.getInt( "OptionPane.messagePadding" );
|
||||
maxCharactersPerLine = UIManager.getInt( "OptionPane.maxCharactersPerLine" );
|
||||
focusWidth = UIManager.getInt( "Component.focusWidth" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMinimumOptionPaneSize() {
|
||||
return UIScale.scale( super.getMinimumOptionPaneSize() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxCharactersPerLineCount() {
|
||||
int max = super.getMaxCharactersPerLineCount();
|
||||
return (maxCharactersPerLine > 0 && max == Integer.MAX_VALUE) ? maxCharactersPerLine : max;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMessageArea() {
|
||||
Container messageArea = super.createMessageArea();
|
||||
|
||||
// set icon-message gap
|
||||
if( iconMessageGap > 0 ) {
|
||||
Component iconMessageSeparator = findByName( messageArea, "OptionPane.separator" );
|
||||
if( iconMessageSeparator != null )
|
||||
iconMessageSeparator.setPreferredSize( new Dimension( UIScale.scale( iconMessageGap ), 1 ) );
|
||||
}
|
||||
|
||||
return messageArea;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createButtonArea() {
|
||||
Container buttonArea = super.createButtonArea();
|
||||
|
||||
// scale button padding and subtract focusWidth
|
||||
if( buttonArea.getLayout() instanceof ButtonAreaLayout ) {
|
||||
ButtonAreaLayout layout = (ButtonAreaLayout) buttonArea.getLayout();
|
||||
layout.setPadding( UIScale.scale( layout.getPadding() - (focusWidth * 2) ) );
|
||||
}
|
||||
|
||||
return buttonArea;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addMessageComponents( Container container, GridBagConstraints cons, Object msg, int maxll,
|
||||
boolean internallyCreated )
|
||||
{
|
||||
// set message padding
|
||||
if( messagePadding > 0 )
|
||||
cons.insets.bottom = UIScale.scale( messagePadding );
|
||||
|
||||
super.addMessageComponents( container, cons, msg, maxll, internallyCreated );
|
||||
}
|
||||
|
||||
private Component findByName( Container c, String name ) {
|
||||
for( Component child : c.getComponents() ) {
|
||||
if( name.equals( child.getName() ) )
|
||||
return child;
|
||||
|
||||
if( child instanceof Container ) {
|
||||
Component c2 = findByName( (Container) child, name );
|
||||
if( c2 != null )
|
||||
return c2;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2019 FormDev Software GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf.util;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||
|
||||
/**
|
||||
* A number that scales its value.
|
||||
*
|
||||
* NOTE:
|
||||
* Using ScaledNumber in UI defaults works only if the value is get with
|
||||
* sun.swing.DefaultLookup.getInt(), which is used by some basic UI delegates,
|
||||
* because this method uses "instanceof Number".
|
||||
* UIManager.getInt() on the other hand uses "instanceof Integer" and does not work.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class ScaledNumber
|
||||
extends Number
|
||||
{
|
||||
private final int value;
|
||||
|
||||
public ScaledNumber( int value ) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intValue() {
|
||||
return scale( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public long longValue() {
|
||||
return scale( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public float floatValue() {
|
||||
return scale( (float) value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public double doubleValue() {
|
||||
return scale( (float) value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Integer.hashCode( value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj ) {
|
||||
return (obj instanceof ScaledNumber)
|
||||
? (value == ((ScaledNumber)obj).value)
|
||||
: false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString( value );
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ ListUI=com.formdev.flatlaf.ui.FlatListUI
|
||||
MenuUI=com.formdev.flatlaf.ui.FlatMenuUI
|
||||
MenuBarUI=com.formdev.flatlaf.ui.FlatMenuBarUI
|
||||
MenuItemUI=com.formdev.flatlaf.ui.FlatMenuItemUI
|
||||
OptionPaneUI=com.formdev.flatlaf.ui.FlatOptionPaneUI
|
||||
PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI
|
||||
PopupMenuUI=com.formdev.flatlaf.ui.FlatPopupMenuUI
|
||||
PopupMenuSeparatorUI=com.formdev.flatlaf.ui.FlatPopupMenuSeparatorUI
|
||||
@@ -130,6 +131,20 @@ MenuItem.arrowIcon=com.formdev.flatlaf.icons.FlatMenuItemArrowIcon
|
||||
|
||||
#---- OptionPane ----
|
||||
|
||||
OptionPane.border=12,12,12,12
|
||||
OptionPane.messageAreaBorder=0,0,0,0
|
||||
OptionPane.buttonAreaBorder=12,0,0,0
|
||||
OptionPane.messageForeground=null
|
||||
|
||||
OptionPane.maxCharactersPerLine=80
|
||||
OptionPane.iconMessageGap=16
|
||||
OptionPane.messagePadding=3
|
||||
OptionPane.buttonPadding=8
|
||||
OptionPane.buttonMinimumWidth=80
|
||||
OptionPane.sameSizeButtons=true
|
||||
OptionPane.setButtonMargin=false
|
||||
OptionPane.buttonOrientation=4
|
||||
|
||||
OptionPane.errorIcon=com.formdev.flatlaf.icons.FlatOptionPaneErrorIcon
|
||||
OptionPane.informationIcon=com.formdev.flatlaf.icons.FlatOptionPaneInformationIcon
|
||||
OptionPane.questionIcon=com.formdev.flatlaf.icons.FlatOptionPaneQuestionIcon
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* Copyright 2019 FormDev Software GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import net.miginfocom.swing.*;
|
||||
|
||||
/**
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatOptionPaneTest
|
||||
extends JPanel
|
||||
{
|
||||
public static void main( String[] args ) {
|
||||
FlatTestFrame frame = FlatTestFrame.create( args, "FlatOptionPaneTest" );
|
||||
frame.showFrame( new FlatOptionPaneTest() );
|
||||
}
|
||||
|
||||
FlatOptionPaneTest() {
|
||||
initComponents();
|
||||
|
||||
customOptionPane.setMessage( new Object[] {
|
||||
"string",
|
||||
"multi-\nline string",
|
||||
new JCheckBox( "check box" ),
|
||||
new JTextField( "text field" ),
|
||||
"more text",
|
||||
} );
|
||||
customOptionPane.setOptions( new Object[] {
|
||||
new JCheckBox( "check me" ),
|
||||
"OK",
|
||||
"Cancel",
|
||||
} );
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||
JLabel plainLabel = new JLabel();
|
||||
JPanel panel1 = new JPanel();
|
||||
JOptionPane plainOptionPane = new JOptionPane();
|
||||
plainShowDialogLabel = new FlatOptionPaneTest.ShowDialogLinkLabel();
|
||||
JLabel errorLabel = new JLabel();
|
||||
JPanel panel2 = new JPanel();
|
||||
JOptionPane errorOptionPane = new JOptionPane();
|
||||
errorShowDialogLabel = new FlatOptionPaneTest.ShowDialogLinkLabel();
|
||||
JLabel informationLabel = new JLabel();
|
||||
JPanel panel3 = new JPanel();
|
||||
JOptionPane informationOptionPane = new JOptionPane();
|
||||
informationShowDialogLabel = new FlatOptionPaneTest.ShowDialogLinkLabel();
|
||||
JLabel questionLabel = new JLabel();
|
||||
JPanel panel4 = new JPanel();
|
||||
JOptionPane questionOptionPane = new JOptionPane();
|
||||
FlatOptionPaneTest.ShowDialogLinkLabel questionShowDialogLabel = new FlatOptionPaneTest.ShowDialogLinkLabel();
|
||||
JLabel warningLabel = new JLabel();
|
||||
JPanel panel5 = new JPanel();
|
||||
JOptionPane warningOptionPane = new JOptionPane();
|
||||
FlatOptionPaneTest.ShowDialogLinkLabel warningShowDialogLabel = new FlatOptionPaneTest.ShowDialogLinkLabel();
|
||||
JLabel inputLabel = new JLabel();
|
||||
JPanel panel7 = new JPanel();
|
||||
JOptionPane inputOptionPane = new JOptionPane();
|
||||
FlatOptionPaneTest.ShowDialogLinkLabel inputShowDialogLabel = new FlatOptionPaneTest.ShowDialogLinkLabel();
|
||||
JLabel inputIconLabel = new JLabel();
|
||||
JPanel panel8 = new JPanel();
|
||||
JOptionPane inputIconOptionPane = new JOptionPane();
|
||||
FlatOptionPaneTest.ShowDialogLinkLabel inputIconShowDialogLabel = new FlatOptionPaneTest.ShowDialogLinkLabel();
|
||||
JLabel customLabel = new JLabel();
|
||||
JPanel panel6 = new JPanel();
|
||||
customOptionPane = new JOptionPane();
|
||||
FlatOptionPaneTest.ShowDialogLinkLabel customShowDialogLabel = new FlatOptionPaneTest.ShowDialogLinkLabel();
|
||||
|
||||
//======== this ========
|
||||
setLayout(new MigLayout(
|
||||
"flowy,ltr,insets 0,hidemode 3,gap 5 5",
|
||||
// columns
|
||||
"[]" +
|
||||
"[]" +
|
||||
"[fill]",
|
||||
// rows
|
||||
"[top]" +
|
||||
"[top]" +
|
||||
"[top]" +
|
||||
"[top]" +
|
||||
"[top]" +
|
||||
"[top]" +
|
||||
"[top]" +
|
||||
"[top]"));
|
||||
|
||||
//---- plainLabel ----
|
||||
plainLabel.setText("Plain");
|
||||
add(plainLabel, "cell 0 0");
|
||||
|
||||
//======== panel1 ========
|
||||
{
|
||||
panel1.setBorder(LineBorder.createGrayLineBorder());
|
||||
panel1.setLayout(new BorderLayout());
|
||||
|
||||
//---- plainOptionPane ----
|
||||
plainOptionPane.setMessage("Hello world.");
|
||||
panel1.add(plainOptionPane, BorderLayout.CENTER);
|
||||
}
|
||||
add(panel1, "cell 1 0");
|
||||
|
||||
//---- plainShowDialogLabel ----
|
||||
plainShowDialogLabel.setOptionPane(plainOptionPane);
|
||||
plainShowDialogLabel.setTitleLabel(plainLabel);
|
||||
add(plainShowDialogLabel, "cell 2 0");
|
||||
|
||||
//---- errorLabel ----
|
||||
errorLabel.setText("Error");
|
||||
add(errorLabel, "cell 0 1");
|
||||
|
||||
//======== panel2 ========
|
||||
{
|
||||
panel2.setBorder(LineBorder.createGrayLineBorder());
|
||||
panel2.setLayout(new BorderLayout());
|
||||
|
||||
//---- errorOptionPane ----
|
||||
errorOptionPane.setMessageType(JOptionPane.ERROR_MESSAGE);
|
||||
errorOptionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
|
||||
errorOptionPane.setMessage("Your PC ran into a problem. Buy a new one.");
|
||||
panel2.add(errorOptionPane, BorderLayout.CENTER);
|
||||
}
|
||||
add(panel2, "cell 1 1");
|
||||
|
||||
//---- errorShowDialogLabel ----
|
||||
errorShowDialogLabel.setTitleLabel(errorLabel);
|
||||
errorShowDialogLabel.setOptionPane(errorOptionPane);
|
||||
add(errorShowDialogLabel, "cell 2 1");
|
||||
|
||||
//---- informationLabel ----
|
||||
informationLabel.setText("Information");
|
||||
add(informationLabel, "cell 0 2");
|
||||
|
||||
//======== panel3 ========
|
||||
{
|
||||
panel3.setBorder(LineBorder.createGrayLineBorder());
|
||||
panel3.setLayout(new BorderLayout());
|
||||
|
||||
//---- informationOptionPane ----
|
||||
informationOptionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
||||
informationOptionPane.setOptionType(JOptionPane.YES_NO_OPTION);
|
||||
informationOptionPane.setMessage("Text with\nmultiple lines\n(use \\n to separate lines)");
|
||||
panel3.add(informationOptionPane, BorderLayout.CENTER);
|
||||
}
|
||||
add(panel3, "cell 1 2");
|
||||
|
||||
//---- informationShowDialogLabel ----
|
||||
informationShowDialogLabel.setOptionPane(informationOptionPane);
|
||||
informationShowDialogLabel.setTitleLabel(informationLabel);
|
||||
add(informationShowDialogLabel, "cell 2 2");
|
||||
|
||||
//---- questionLabel ----
|
||||
questionLabel.setText("Question");
|
||||
add(questionLabel, "cell 0 3");
|
||||
|
||||
//======== panel4 ========
|
||||
{
|
||||
panel4.setBorder(LineBorder.createGrayLineBorder());
|
||||
panel4.setLayout(new BorderLayout());
|
||||
|
||||
//---- questionOptionPane ----
|
||||
questionOptionPane.setMessageType(JOptionPane.QUESTION_MESSAGE);
|
||||
questionOptionPane.setOptionType(JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
questionOptionPane.setMessage("Answer the question. What question? Don't know. Just writing useless text to make this longer than 80 characters.");
|
||||
panel4.add(questionOptionPane, BorderLayout.CENTER);
|
||||
}
|
||||
add(panel4, "cell 1 3");
|
||||
|
||||
//---- questionShowDialogLabel ----
|
||||
questionShowDialogLabel.setOptionPane(questionOptionPane);
|
||||
questionShowDialogLabel.setTitleLabel(questionLabel);
|
||||
add(questionShowDialogLabel, "cell 2 3");
|
||||
|
||||
//---- warningLabel ----
|
||||
warningLabel.setText("Warning");
|
||||
add(warningLabel, "cell 0 4");
|
||||
|
||||
//======== panel5 ========
|
||||
{
|
||||
panel5.setBorder(LineBorder.createGrayLineBorder());
|
||||
panel5.setLayout(new BorderLayout());
|
||||
|
||||
//---- warningOptionPane ----
|
||||
warningOptionPane.setMessageType(JOptionPane.WARNING_MESSAGE);
|
||||
warningOptionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
|
||||
warningOptionPane.setMessage("Beware of the dog!");
|
||||
panel5.add(warningOptionPane, BorderLayout.CENTER);
|
||||
}
|
||||
add(panel5, "cell 1 4");
|
||||
|
||||
//---- warningShowDialogLabel ----
|
||||
warningShowDialogLabel.setOptionPane(warningOptionPane);
|
||||
warningShowDialogLabel.setTitleLabel(warningLabel);
|
||||
add(warningShowDialogLabel, "cell 2 4");
|
||||
|
||||
//---- inputLabel ----
|
||||
inputLabel.setText("Input");
|
||||
add(inputLabel, "cell 0 5");
|
||||
|
||||
//======== panel7 ========
|
||||
{
|
||||
panel7.setBorder(LineBorder.createGrayLineBorder());
|
||||
panel7.setLayout(new BorderLayout());
|
||||
|
||||
//---- inputOptionPane ----
|
||||
inputOptionPane.setWantsInput(true);
|
||||
inputOptionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
|
||||
inputOptionPane.setMessage("Enter whatever you want:");
|
||||
panel7.add(inputOptionPane, BorderLayout.CENTER);
|
||||
}
|
||||
add(panel7, "cell 1 5");
|
||||
|
||||
//---- inputShowDialogLabel ----
|
||||
inputShowDialogLabel.setOptionPane(inputOptionPane);
|
||||
inputShowDialogLabel.setTitleLabel(inputLabel);
|
||||
add(inputShowDialogLabel, "cell 2 5");
|
||||
|
||||
//---- inputIconLabel ----
|
||||
inputIconLabel.setText("Input + icon");
|
||||
add(inputIconLabel, "cell 0 6");
|
||||
|
||||
//======== panel8 ========
|
||||
{
|
||||
panel8.setBorder(LineBorder.createGrayLineBorder());
|
||||
panel8.setLayout(new BorderLayout());
|
||||
|
||||
//---- inputIconOptionPane ----
|
||||
inputIconOptionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
|
||||
inputIconOptionPane.setWantsInput(true);
|
||||
inputIconOptionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
|
||||
inputIconOptionPane.setMessage("Enter something:");
|
||||
panel8.add(inputIconOptionPane, BorderLayout.CENTER);
|
||||
}
|
||||
add(panel8, "cell 1 6");
|
||||
|
||||
//---- inputIconShowDialogLabel ----
|
||||
inputIconShowDialogLabel.setTitleLabel(inputIconLabel);
|
||||
inputIconShowDialogLabel.setOptionPane(inputIconOptionPane);
|
||||
add(inputIconShowDialogLabel, "cell 2 6");
|
||||
|
||||
//---- customLabel ----
|
||||
customLabel.setText("Custom");
|
||||
add(customLabel, "cell 0 7");
|
||||
|
||||
//======== panel6 ========
|
||||
{
|
||||
panel6.setBorder(LineBorder.createGrayLineBorder());
|
||||
panel6.setLayout(new BorderLayout());
|
||||
|
||||
//---- customOptionPane ----
|
||||
customOptionPane.setIcon(UIManager.getIcon("Tree.leafIcon"));
|
||||
panel6.add(customOptionPane, BorderLayout.CENTER);
|
||||
}
|
||||
add(panel6, "cell 1 7");
|
||||
|
||||
//---- customShowDialogLabel ----
|
||||
customShowDialogLabel.setOptionPane(customOptionPane);
|
||||
customShowDialogLabel.setTitleLabel(customLabel);
|
||||
add(customShowDialogLabel, "cell 2 7");
|
||||
// JFormDesigner - End of component initialization //GEN-END:initComponents
|
||||
}
|
||||
|
||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
||||
private FlatOptionPaneTest.ShowDialogLinkLabel plainShowDialogLabel;
|
||||
private FlatOptionPaneTest.ShowDialogLinkLabel errorShowDialogLabel;
|
||||
private FlatOptionPaneTest.ShowDialogLinkLabel informationShowDialogLabel;
|
||||
private JOptionPane customOptionPane;
|
||||
// JFormDesigner - End of variables declaration //GEN-END:variables
|
||||
|
||||
//---- class ShowDialogLinkLabel ------------------------------------------
|
||||
|
||||
private static class ShowDialogLinkLabel
|
||||
extends JLabel
|
||||
{
|
||||
private JLabel titleLabel;
|
||||
private JOptionPane optionPane;
|
||||
|
||||
ShowDialogLinkLabel() {
|
||||
setText( "<html><a href=\"#\">Show dialog</a></html>" );
|
||||
|
||||
addMouseListener( new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked( MouseEvent e ) {
|
||||
showDialog();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private void showDialog() {
|
||||
if( optionPane.getWantsInput() ) {
|
||||
JOptionPane.showInputDialog(
|
||||
getParent(),
|
||||
optionPane.getMessage(),
|
||||
titleLabel.getText() + " Title",
|
||||
optionPane.getMessageType(),
|
||||
optionPane.getIcon(),
|
||||
null,
|
||||
null );
|
||||
} else {
|
||||
JOptionPane.showOptionDialog(
|
||||
getParent(),
|
||||
optionPane.getMessage(),
|
||||
titleLabel.getText() + " Title",
|
||||
optionPane.getOptionType(),
|
||||
optionPane.getMessageType(),
|
||||
optionPane.getIcon(),
|
||||
optionPane.getOptions(),
|
||||
optionPane.getInitialValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unused" )
|
||||
public JLabel getTitleLabel() {
|
||||
return titleLabel;
|
||||
}
|
||||
|
||||
public void setTitleLabel( JLabel titleLabel ) {
|
||||
this.titleLabel = titleLabel;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unused" )
|
||||
public JOptionPane getOptionPane() {
|
||||
return optionPane;
|
||||
}
|
||||
|
||||
public void setOptionPane( JOptionPane optionPane ) {
|
||||
this.optionPane = optionPane;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
JFDML JFormDesigner: "7.0.0.0.194" Java: "11.0.2" encoding: "UTF-8"
|
||||
|
||||
new FormModel {
|
||||
contentType: "form/swing"
|
||||
root: new FormRoot {
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.defaultVariableLocal": true
|
||||
}
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
|
||||
"$layoutConstraints": "flowy,ltr,insets 0,hidemode 3,gap 5 5"
|
||||
"$columnConstraints": "[][][fill]"
|
||||
"$rowConstraints": "[top][top][top][top][top][top][top][top]"
|
||||
} ) {
|
||||
name: "this"
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "plainLabel"
|
||||
"text": "Plain"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 0"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||
name: "panel1"
|
||||
"border": &LineBorder0 new javax.swing.border.LineBorder( sfield java.awt.Color gray, 1, false )
|
||||
add( new FormComponent( "javax.swing.JOptionPane" ) {
|
||||
name: "plainOptionPane"
|
||||
"message": "Hello world."
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "Center"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 0"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.FlatOptionPaneTest$ShowDialogLinkLabel" ) {
|
||||
name: "plainShowDialogLabel"
|
||||
"optionPane": new FormReference( "plainOptionPane" )
|
||||
"titleLabel": new FormReference( "plainLabel" )
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 0"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "errorLabel"
|
||||
"text": "Error"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 1"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||
name: "panel2"
|
||||
"border": #LineBorder0
|
||||
add( new FormComponent( "javax.swing.JOptionPane" ) {
|
||||
name: "errorOptionPane"
|
||||
"messageType": 0
|
||||
"optionType": 2
|
||||
"message": "Your PC ran into a problem. Buy a new one."
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "Center"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 1"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.FlatOptionPaneTest$ShowDialogLinkLabel" ) {
|
||||
name: "errorShowDialogLabel"
|
||||
"titleLabel": new FormReference( "errorLabel" )
|
||||
"optionPane": new FormReference( "errorOptionPane" )
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 1"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "informationLabel"
|
||||
"text": "Information"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 2"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||
name: "panel3"
|
||||
"border": #LineBorder0
|
||||
add( new FormComponent( "javax.swing.JOptionPane" ) {
|
||||
name: "informationOptionPane"
|
||||
"messageType": 1
|
||||
"optionType": 0
|
||||
"message": "Text with\nmultiple lines\n(use \\n to separate lines)"
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "Center"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 2"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.FlatOptionPaneTest$ShowDialogLinkLabel" ) {
|
||||
name: "informationShowDialogLabel"
|
||||
"optionPane": new FormReference( "informationOptionPane" )
|
||||
"titleLabel": new FormReference( "informationLabel" )
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 2"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "questionLabel"
|
||||
"text": "Question"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 3"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||
name: "panel4"
|
||||
"border": #LineBorder0
|
||||
add( new FormComponent( "javax.swing.JOptionPane" ) {
|
||||
name: "questionOptionPane"
|
||||
"messageType": 3
|
||||
"optionType": 1
|
||||
"message": "Answer the question. What question? Don't know. Just writing useless text to make this longer than 80 characters."
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "Center"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 3"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.FlatOptionPaneTest$ShowDialogLinkLabel" ) {
|
||||
name: "questionShowDialogLabel"
|
||||
"optionPane": new FormReference( "questionOptionPane" )
|
||||
"titleLabel": new FormReference( "questionLabel" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 3"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "warningLabel"
|
||||
"text": "Warning"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 4"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||
name: "panel5"
|
||||
"border": #LineBorder0
|
||||
add( new FormComponent( "javax.swing.JOptionPane" ) {
|
||||
name: "warningOptionPane"
|
||||
"messageType": 2
|
||||
"optionType": 2
|
||||
"message": "Beware of the dog!"
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "Center"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 4"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.FlatOptionPaneTest$ShowDialogLinkLabel" ) {
|
||||
name: "warningShowDialogLabel"
|
||||
"optionPane": new FormReference( "warningOptionPane" )
|
||||
"titleLabel": new FormReference( "warningLabel" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 4"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "inputLabel"
|
||||
"text": "Input"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 5"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||
name: "panel7"
|
||||
"border": #LineBorder0
|
||||
add( new FormComponent( "javax.swing.JOptionPane" ) {
|
||||
name: "inputOptionPane"
|
||||
"wantsInput": true
|
||||
"optionType": 2
|
||||
"message": "Enter whatever you want:"
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "Center"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 5"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.FlatOptionPaneTest$ShowDialogLinkLabel" ) {
|
||||
name: "inputShowDialogLabel"
|
||||
"optionPane": new FormReference( "inputOptionPane" )
|
||||
"titleLabel": new FormReference( "inputLabel" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 5"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "inputIconLabel"
|
||||
"text": "Input + icon"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 6"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||
name: "panel8"
|
||||
"border": #LineBorder0
|
||||
add( new FormComponent( "javax.swing.JOptionPane" ) {
|
||||
name: "inputIconOptionPane"
|
||||
"messageType": 1
|
||||
"wantsInput": true
|
||||
"optionType": 2
|
||||
"message": "Enter something:"
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "Center"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 6"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.FlatOptionPaneTest$ShowDialogLinkLabel" ) {
|
||||
name: "inputIconShowDialogLabel"
|
||||
"titleLabel": new FormReference( "inputIconLabel" )
|
||||
"optionPane": new FormReference( "inputIconOptionPane" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 6"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "customLabel"
|
||||
"text": "Custom"
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 0 7"
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class java.awt.BorderLayout ) ) {
|
||||
name: "panel6"
|
||||
"border": #LineBorder0
|
||||
add( new FormComponent( "javax.swing.JOptionPane" ) {
|
||||
name: "customOptionPane"
|
||||
"icon": new com.jformdesigner.model.SwingIcon( 2, "Tree.leafIcon" )
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
}, new FormLayoutConstraints( class java.lang.String ) {
|
||||
"value": "Center"
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 7"
|
||||
} )
|
||||
add( new FormComponent( "com.formdev.flatlaf.FlatOptionPaneTest$ShowDialogLinkLabel" ) {
|
||||
name: "customShowDialogLabel"
|
||||
"optionPane": new FormReference( "customOptionPane" )
|
||||
"titleLabel": new FormReference( "customLabel" )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 2 7"
|
||||
} )
|
||||
}, new FormLayoutConstraints( null ) {
|
||||
"location": new java.awt.Point( 0, 0 )
|
||||
"size": new java.awt.Dimension( 790, 840 )
|
||||
} )
|
||||
}
|
||||
}
|
||||
@@ -144,6 +144,10 @@ public class FlatTestFrame
|
||||
pack();
|
||||
setLocationRelativeTo( null );
|
||||
setVisible( true );
|
||||
|
||||
EventQueue.invokeLater( () -> {
|
||||
closeButton.requestFocusInWindow();
|
||||
} );
|
||||
}
|
||||
|
||||
private void selectLookAndFeel( String lafClassName ) {
|
||||
|
||||
Reference in New Issue
Block a user