Adding a listener to close button on a JFrame
can I add an action listener to the 'x' button on a JFrame? i want to ask the user if they wish to save when they click the close button on the JFrame...
thanks.
Set the default close operation on your frame to do nothing and use a WindowListener, like so:
import java.awt.event.*;
import javax.swing.*;
public class AskBeforeCloseTest extends JFrame {
public AskBeforeCloseTest() {
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int ret = JOptionPane.showOptionDialog(
AskBeforeCloseTest.this,
"Do you want to quit?",
"Quit?",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
null,
null);
if( ret == JOptionPane.YES_OPTION ) {
System.exit(0);
getContentPane().add(new JLabel("Hello"));
pack();
setLocationRelativeTo(null);
public static void main(String[] args) {
new AskBeforeCloseTest().setVisible(true);
}
Similar Messages
-
Adding a listener to ALL buttons
I have about 70 buttons on a page - and I want all of them to
get the same eventlistener... can I add it to all of them with one
fell swoop?Are these Flash Component UI buttons or your own custom
buttons?
With Flash Component UI buttons, this is not a problem. Ex:
function buttons_clicked(evt_obj)
trace ("seventyButtons_clicked()")
trace ("evt_obj.target:" + evt_obj.target._name )
switch(evt_obj.target)
case one_button:
// do something
break;
case two_button:
// do something
break;
case three_button:
// do something
break;
one_button.addEventListener("click", buttons_clicked);
two_button.addEventListener("click", buttons_clicked);
three_button.addEventListener("click", buttons_clicked);
With custom buttons you have a programmers choice on how to
do it. Here is
one basic way
one_btn.onRelease = two_btn.onRelease = three_btn.onRelease =
function()
trace(this)
switch (this)
case _level0.one_btn:
// do something
break;
case _level0.two_btn:
// do something
break;
case _level0.three_btn:
// do something
break;
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
"matecito" <[email protected]> wrote in
message
news:e2urkb$p7b$[email protected]..
I have about 70 buttons on a page - and I want all of them to
get the same
eventlistener... can I add it to all of them with one fell
swoop? -
Adding Icon and increasing width of tabpages to show the close button in a tabcontrol
I have this code right now,
Public Class FSMTabControl
Inherits TabControl
#Region "Declarations"
Private _TextColour As Color = Color.FromArgb(255, 255, 255)
Private _BackTabColour As Color = Color.FromArgb(54, 54, 54)
Private _BaseColour As Color = Color.FromArgb(35, 35, 35)
Private _ActiveColour As Color = Color.FromArgb(47, 47, 47)
Private _BorderColour As Color = Color.FromArgb(30, 30, 30)
Private _UpLineColour As Color = Color.FromArgb(0, 160, 199)
Private _HorizLineColour As Color = Color.FromArgb(23, 119, 151)
Private CenterSF As New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
#End Region
#Region "Properties"
<Category("Colours")> _
Public Property BorderColour As Color
Get
Return _BorderColour
End Get
Set(value As Color)
_BorderColour = value
End Set
End Property
<Category("Colours")> _
Public Property UpLineColour As Color
Get
Return _UpLineColour
End Get
Set(value As Color)
_UpLineColour = value
End Set
End Property
<Category("Colours")> _
Public Property HorizontalLineColour As Color
Get
Return _HorizLineColour
End Get
Set(value As Color)
_HorizLineColour = value
End Set
End Property
<Category("Colours")> _
Public Property TextColour As Color
Get
Return _TextColour
End Get
Set(value As Color)
_TextColour = value
End Set
End Property
<Category("Colours")> _
Public Property BackTabColour As Color
Get
Return _BackTabColour
End Get
Set(value As Color)
_BackTabColour = value
End Set
End Property
<Category("Colours")> _
Public Property BaseColour As Color
Get
Return _BaseColour
End Get
Set(value As Color)
_BaseColour = value
End Set
End Property
<Category("Colours")> _
Public Property ActiveColour As Color
Get
Return _ActiveColour
End Get
Set(value As Color)
_ActiveColour = value
End Set
End Property
Protected Overrides Sub CreateHandle()
MyBase.CreateHandle()
Alignment = TabAlignment.Bottom
End Sub
#End Region
#Region "Draw Control"
Sub New()
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
DoubleBuffered = True
Font = New Font("Segoe UI", 10)
SizeMode = TabSizeMode.FillToRight
ItemSize = New Size(240, 32)
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Dim g = e.Graphics
With G
.SmoothingMode = SmoothingMode.HighQuality
.PixelOffsetMode = PixelOffsetMode.HighQuality
.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
.Clear(_BaseColour)
Try : SelectedTab.BackColor = _BackTabColour : Catch : End Try
Try : SelectedTab.BorderStyle = BorderStyle.FixedSingle : Catch : End Try
.DrawRectangle(New Pen(_BorderColour, 2), New Rectangle(0, 0, Width, Height))
For i = 0 To TabCount - 1
Dim Base As New Rectangle(New Point(GetTabRect(i).Location.X, GetTabRect(i).Location.Y), New Size(GetTabRect(i).Width, GetTabRect(i).Height))
Dim BaseSize As New Rectangle(Base.Location, New Size(Base.Width, Base.Height))
If i = SelectedIndex Then
.FillRectangle(New SolidBrush(_BaseColour), BaseSize)
.FillRectangle(New SolidBrush(_ActiveColour), New Rectangle(Base.X + 1, Base.Y - 3, Base.Width, Base.Height + 5))
.DrawString(TabPages(i).Text, Font, New SolidBrush(_TextColour), New Rectangle(Base.X + 7, Base.Y, Base.Width - 3, Base.Height), CenterSF)
.DrawLine(New Pen(_HorizLineColour, 2), New Point(Base.X + 3, CInt(Base.Height / 2 + 2)), New Point(Base.X + 9, CInt(Base.Height / 2 + 2)))
.DrawLine(New Pen(_UpLineColour, 2), New Point(Base.X + 3, Base.Y - 3), New Point(Base.X + 3, Base.Height + 5))
Else
.DrawString(TabPages(i).Text, Font, New SolidBrush(_TextColour), BaseSize, CenterSF)
End If
Next
.InterpolationMode = InterpolationMode.HighQualityBicubic
End With
End Sub
Private Declare Auto Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
Protected CloseButtonCollection As New Dictionary(Of Button, TabPage)
Private _ShowCloseButtonOnTabs As Boolean = True
<Browsable(True), DefaultValue(True), Category("Behavior"), Description("Indicates whether a close button should be shown on each TabPage")> _
Public Property ShowCloseButtonOnTabs() As Boolean
Get
Return _ShowCloseButtonOnTabs
End Get
Set(ByVal value As Boolean)
_ShowCloseButtonOnTabs = value
For Each btn In CloseButtonCollection.Keys
btn.Visible = _ShowCloseButtonOnTabs
Next
RePositionCloseButtons()
End Set
End Property
Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
RePositionCloseButtons()
End Sub
Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs)
MyBase.OnControlAdded(e)
Dim tp As TabPage = DirectCast(e.Control, TabPage)
Dim rect As Rectangle = Me.GetTabRect(Me.TabPages.IndexOf(tp))
Dim btn As Button = AddCloseButton(tp)
btn.Size = New Size(CInt(rect.Height / 2), CInt(rect.Height / 2))
btn.Location = New Point(rect.X + rect.Width - rect.Height + 11, CInt(rect.Y + 7))
SetParent(btn.Handle, Me.Handle)
AddHandler btn.Click, AddressOf OnCloseButtonClick
CloseButtonCollection.Add(btn, tp)
End Sub
Protected Overrides Sub OnControlRemoved(ByVal e As System.Windows.Forms.ControlEventArgs)
Dim btn As Button = CloseButtonOfTabPage(DirectCast(e.Control, TabPage))
RemoveHandler btn.Click, AddressOf OnCloseButtonClick
CloseButtonCollection.Remove(btn)
SetParent(btn.Handle, Nothing)
btn.Dispose()
MyBase.OnControlRemoved(e)
End Sub
Protected Overrides Sub OnLayout(ByVal levent As System.Windows.Forms.LayoutEventArgs)
MyBase.OnLayout(levent)
RePositionCloseButtons()
End Sub
Public Event CloseButtonClick As CancelEventHandler
Protected Overridable Sub OnCloseButtonClick(ByVal sender As Object, ByVal e As EventArgs)
If Not DesignMode Then
Dim btn As Button = DirectCast(sender, Button)
Dim tp As TabPage = CloseButtonCollection(btn)
Dim ee As New CancelEventArgs
RaiseEvent CloseButtonClick(sender, ee)
If Not ee.Cancel Then
Me.TabPages.Remove(tp)
RePositionCloseButtons()
End If
End If
End Sub
Protected Overridable Function AddCloseButton(ByVal tp As TabPage) As Button
Dim closeButton As New Button
With closeButton
'' TODO: Give a good visual appearance to the Close button, maybe by assigning images etc.
'' Here I have not used images to keep things simple.
.Text = "X"
.FlatStyle = FlatStyle.Flat
.BackColor = _BaseColour
.ForeColor = Color.White
.Font = New Font("Microsoft Sans Serif", 6, FontStyle.Bold)
End With
Return closeButton
End Function
Public Sub RePositionCloseButtons()
For Each item In CloseButtonCollection
RePositionCloseButtons(item.Value)
Next
End Sub
Public Sub RePositionCloseButtons(ByVal tp As TabPage)
Dim btn As Button = CloseButtonOfTabPage(tp)
If btn IsNot Nothing Then
Dim tpIndex As Integer = Me.TabPages.IndexOf(tp)
If tpIndex >= 0 Then
Dim rect As Rectangle = Me.GetTabRect(tpIndex)
If Me.SelectedTab Is tp Then
btn.BackColor = Color.Red
btn.Size = New Size(CInt(rect.Height / 2), CInt(rect.Height / 2))
btn.Location = New Point(rect.X + rect.Width - rect.Height + 11, CInt(rect.Y + 7))
Else
btn.BackColor = _BaseColour
btn.Size = New Size(CInt(rect.Height / 2), CInt(rect.Height / 2))
btn.Location = New Point(rect.X + rect.Width - rect.Height + 11, CInt(rect.Y + 7))
End If
btn.Visible = ShowCloseButtonOnTabs
btn.BringToFront()
End If
End If
End Sub
Protected Function CloseButtonOfTabPage(ByVal tp As TabPage) As Button
Return (From item In CloseButtonCollection Where item.Value Is tp Select item.Key).FirstOrDefault
End Function
#End Region
End Class
This code shows a perfect tabcontrol as in the picture below,
I managed to get this code working by combining three other VB themes I found. Right now, I just want to increase the width of the tab so the close button doesn't hides the text. And I want to add a icon to the left of the tab and be able to change it on
runtime.
The icons name will be on, off, 1, 2, plus .ico
Is it possible ? and is it possible to make the tabs curved at the corner like in chrome.Hi,
I have went through your TabControl class and changed it around a little bit to get something similar to what i think you want. I made it so that the Tabs are resized with the TabControl itself so that they always fill the width of the TabControl.
I also, made the Text of the tabs have its own rectangle which will automatically adjust it`s width according to weather or not the close buttons are shown so the text will never be under the buttons.
As for the Icons, you could create another small class that inherits from the TabPage base class and add a public property to it for the Icon image. You would have to use that class to add TabPages and set the Icon property. Then in the
TabControl class`s OnPaint overrides sub you would check if the Icon property of the TabPage is set and draw the image if it is.
I didn`t go that far but, i used the TabPage`s Tag property for the Icon image. Actually it is just an Image, not an Icon. So, in the TabControl`s OnPaint overrides sub i check if the TabPage`s Tag property is set to an Image and if it
is i adjust the Text rectangle to avoid the Image and draw the image.
I moved the StringFormat to the OnPaint sub and set it to keep the text left aligned so it stayed next to the Image. You can change it back to the Center if you want. I also set the StringFormat trimming to EllipsisCharacter so it will
cut the text off if it is to long to fit between the Image and the Close button.
You can test it in a new form project first and to check out how it works and what i changed.
Imports System.ComponentModel
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Public Class FSMTabControl
Inherits TabControl
#Region "Declarations"
Private _TextColour As Color = Color.FromArgb(255, 255, 255)
Private _BackTabColour As Color = Color.FromArgb(54, 54, 54)
Private _BaseColour As Color = Color.FromArgb(35, 35, 35)
Private _ActiveColour As Color = Color.FromArgb(47, 47, 47)
Private _BorderColour As Color = Color.FromArgb(30, 30, 30)
Private _UpLineColour As Color = Color.FromArgb(0, 160, 199)
Private _HorizLineColour As Color = Color.FromArgb(23, 119, 151)
#End Region
#Region "Properties"
<Category("Colours")> _
Public Property BorderColour() As Color
Get
Return _BorderColour
End Get
Set(ByVal value As Color)
_BorderColour = value
End Set
End Property
<Category("Colours")> _
Public Property UpLineColour() As Color
Get
Return _UpLineColour
End Get
Set(ByVal value As Color)
_UpLineColour = value
End Set
End Property
<Category("Colours")> _
Public Property HorizontalLineColour() As Color
Get
Return _HorizLineColour
End Get
Set(ByVal value As Color)
_HorizLineColour = value
End Set
End Property
<Category("Colours")> _
Public Property TextColour() As Color
Get
Return _TextColour
End Get
Set(ByVal value As Color)
_TextColour = value
End Set
End Property
<Category("Colours")> _
Public Property BackTabColour() As Color
Get
Return _BackTabColour
End Get
Set(ByVal value As Color)
_BackTabColour = value
End Set
End Property
<Category("Colours")> _
Public Property BaseColour() As Color
Get
Return _BaseColour
End Get
Set(ByVal value As Color)
_BaseColour = value
End Set
End Property
<Category("Colours")> _
Public Property ActiveColour() As Color
Get
Return _ActiveColour
End Get
Set(ByVal value As Color)
_ActiveColour = value
End Set
End Property
Protected Overrides Sub CreateHandle()
MyBase.CreateHandle()
Alignment = TabAlignment.Bottom
End Sub
#End Region
#Region "Draw Control"
Sub New()
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
DoubleBuffered = True
Font = New Font("Segoe UI", 10)
SizeMode = TabSizeMode.Fixed
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
With e.Graphics
.SmoothingMode = SmoothingMode.HighQuality
.PixelOffsetMode = PixelOffsetMode.HighQuality
.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
.Clear(_BaseColour)
Try : SelectedTab.BackColor = _BackTabColour : Catch : End Try
Try : SelectedTab.BorderStyle = BorderStyle.FixedSingle : Catch : End Try
.DrawRectangle(New Pen(_BorderColour, 2), New Rectangle(0, 0, Width, Height))
If Me.Created AndAlso Me.TabCount > 0 Then
Dim tw As Integer = CInt(Me.ClientSize.Width / Me.TabCount)
Dim offset As Integer = Me.TabCount
If Me.ItemSize.Width <> tw - offset Then Me.ItemSize = New Size(tw - offset, 32)
End If
Using CenterSF As New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Center, .Trimming = StringTrimming.EllipsisCharacter, .FormatFlags = StringFormatFlags.NoWrap}
For i As Integer = 0 To TabCount - 1
Dim Base As Rectangle = Me.GetTabRect(i)
Dim txtrect As New Rectangle(Base.Left, Base.Top, Base.Width, Base.Height)
Dim img As Image = Nothing
If Me.TabPages(i).Tag IsNot Nothing Then
txtrect.X += Base.Height
txtrect.Width -= Base.Height
img = DirectCast(Me.TabPages(i).Tag, Image)
End If
If ShowCloseButtonOnTabs Then
txtrect.Width -= Base.Height
End If
If i = SelectedIndex Then
.FillRectangle(New SolidBrush(_BaseColour), Base)
.FillRectangle(New SolidBrush(_ActiveColour), New Rectangle(Base.X + 1, Base.Y - 3, Base.Width, Base.Height + 4))
.DrawString(TabPages(i).Text, Font, New SolidBrush(_TextColour), txtrect, CenterSF)
.DrawLine(New Pen(_HorizLineColour, 2), New Point(Base.X + 3, CInt(Base.Height / 2 + 2)), New Point(Base.X + 9, CInt(Base.Height / 2 + 2)))
.DrawLine(New Pen(_UpLineColour, 2), New Point(Base.X + 3, Base.Y - 3), New Point(Base.X + 3, Base.Height + 5))
Else
.DrawString(TabPages(i).Text, Font, New SolidBrush(_TextColour), txtrect, CenterSF)
End If
If img IsNot Nothing Then
.DrawImage(img, Base.Left + 2, Base.Top + 2, Base.Height - 4, Base.Height - 4)
End If
Next
End Using
.InterpolationMode = InterpolationMode.HighQualityBicubic
End With
End Sub
Private Declare Auto Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
Protected CloseButtonCollection As New Dictionary(Of Button, TabPage)
Private _ShowCloseButtonOnTabs As Boolean = True
<Browsable(True), DefaultValue(True), Category("Behavior"), Description("Indicates whether a close button should be shown on each TabPage")> _
Public Property ShowCloseButtonOnTabs() As Boolean
Get
Return _ShowCloseButtonOnTabs
End Get
Set(ByVal value As Boolean)
_ShowCloseButtonOnTabs = value
For Each btn As Button In CloseButtonCollection.Keys
btn.Visible = _ShowCloseButtonOnTabs
Next
RePositionCloseButtons()
Me.Refresh()
End Set
End Property
Protected Overrides Sub OnCreateControl()
MyBase.OnCreateControl()
RePositionCloseButtons()
End Sub
Protected Overrides Sub OnControlAdded(ByVal e As System.Windows.Forms.ControlEventArgs)
MyBase.OnControlAdded(e)
Dim tp As TabPage = DirectCast(e.Control, TabPage)
Dim rect As Rectangle = Me.GetTabRect(Me.TabPages.IndexOf(tp))
Dim btn As Button = AddCloseButton(tp)
btn.Size = New Size(CInt(rect.Height / 2), CInt(rect.Height / 2))
btn.Location = New Point(rect.X + rect.Width - rect.Height + 11, CInt(rect.Y + 7))
SetParent(btn.Handle, Me.Handle)
AddHandler btn.Click, AddressOf OnCloseButtonClick
'ResizeTabs()
CloseButtonCollection.Add(btn, tp)
End Sub
Protected Overrides Sub OnControlRemoved(ByVal e As System.Windows.Forms.ControlEventArgs)
Dim btn As Button = CloseButtonOfTabPage(DirectCast(e.Control, TabPage))
RemoveHandler btn.Click, AddressOf OnCloseButtonClick
CloseButtonCollection.Remove(btn)
SetParent(btn.Handle, Nothing)
btn.Dispose()
MyBase.OnControlRemoved(e)
'ResizeTabs()
End Sub
Protected Overrides Sub OnLayout(ByVal levent As System.Windows.Forms.LayoutEventArgs)
MyBase.OnLayout(levent)
RePositionCloseButtons()
End Sub
Public Event CloseButtonClick As CancelEventHandler
Protected Overridable Sub OnCloseButtonClick(ByVal sender As Object, ByVal e As EventArgs)
If Not DesignMode Then
Dim btn As Button = DirectCast(sender, Button)
Dim tp As TabPage = CloseButtonCollection(btn)
Dim ee As New CancelEventArgs
RaiseEvent CloseButtonClick(sender, ee)
If Not ee.Cancel Then
Me.TabPages.Remove(tp)
RePositionCloseButtons()
End If
End If
End Sub
Protected Overridable Function AddCloseButton(ByVal tp As TabPage) As Button
Dim closeButton As New Button
With closeButton
'' TODO: Give a good visual appearance to the Close button, maybe by assigning images etc.
'' Here I have not used images to keep things simple.
.Text = "X"
.FlatStyle = FlatStyle.Flat
.BackColor = _BaseColour
.ForeColor = Color.White
.Font = New Font("Microsoft Sans Serif", 6, FontStyle.Bold)
End With
Return closeButton
End Function
Public Sub RePositionCloseButtons()
For Each item As KeyValuePair(Of Button, TabPage) In CloseButtonCollection
RePositionCloseButtons(item.Value)
Next
End Sub
Public Sub RePositionCloseButtons(ByVal tp As TabPage)
Dim btn As Button = CloseButtonOfTabPage(tp)
If btn IsNot Nothing Then
Dim tpIndex As Integer = Me.TabPages.IndexOf(tp)
If tpIndex >= 0 Then
Dim rect As Rectangle = Me.GetTabRect(tpIndex)
If Me.SelectedTab Is tp Then
btn.BackColor = Color.Red
btn.Size = New Size(CInt(rect.Height / 2), CInt(rect.Height / 2))
btn.Location = New Point(rect.Right - rect.Height + 11, CInt(rect.Y + 7))
Else
btn.BackColor = _BaseColour
btn.Size = New Size(CInt(rect.Height / 2), CInt(rect.Height / 2))
btn.Location = New Point(rect.Right - rect.Height + 11, CInt(rect.Y + 7))
End If
btn.Visible = ShowCloseButtonOnTabs
btn.BringToFront()
End If
End If
End Sub
Protected Function CloseButtonOfTabPage(ByVal tp As TabPage) As Button
Return (From item In CloseButtonCollection Where item.Value Is tp Select item.Key).FirstOrDefault
End Function
#End Region
End Class
In the Form`s code you can set the images for the TabPage icons like this.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TabPage1.Tag = Image.FromFile("C:\testfolder\img1.png")
Me.TabPage2.Tag = Image.FromFile("C:\testfolder\img2.png")
End Sub
End Class
Here is an example of what it looks like.
If you say it can`t be done then i`ll try it
Thanks :)) I tried you code and it works perfectly.
Though i don't want the tabs have their width's by the size of form, so i fixed a width,
If Me.Created AndAlso Me.TabCount > 0 Then
'Dim tw As Integer = CInt(Me.ClientSize.Width / Me.TabCount)
'Dim offset As Integer = Me.TabCount
'If Me.ItemSize.Width <> tw - offset Then Me.ItemSize = New Size(tw - offset, 32)
Me.ItemSize = New Size(200, 32)
End If
Here is the screenshot,
I just don't know why the arrows (left and right) aren't full. here is a gif,
Why is that :O Should I paint the arrows as well ? -
Accessing Close button in TitleWindow
Hi all,
I have a situation where I'm adding buttons to a TitleWindow
chrome. They co-exist with the close button provided by the panel.
I create classes for my button images and then I size the buttons
to fit the image.
I also set the styles for the panel-provided close button
with classes. My goal was to have all the buttons look & feel
the same.
Excerpt from application mxmxl ...
<mx:Style>
TitleWindow {
backgroundColor: #333333;
closeButtonDisabledSkin: Embed("assets/close.png");
closeButtonDownSkin: Embed("assets/closeDown.png");
closeButtonOverSkin: Embed("assets/closeDown.png");
closeButtonUpSkin: Embed("assets/closeUp.png");
</mx:Style>
<v:ResizeWindow id="testResizeWindow"
height="50%"
width="50%"
title="Resize Window"
useWindowButtons="true"
status=""
showCloseButton="true"
restoreWindow="this.currentState=''"
maximizeWindow="this.currentState='maximized'"
minimizeWindow="this.currentState='minimized'"
close="popUp('Close button clicked')">
</v:ResizeWindow>
Excerpt from my ResizeWindow class ...
override protected function createChildren():void{
super.createChildren();
if(useWindowButtons){
if(btnMinimize == null){
btnMinimize = new Button();
var btnMinimizeImageObj:BitmapAsset = new
btnMinimizeUpSkin() as BitmapAsset;
btnMinimize.width = btnMinimizeImageObj.width;
btnMinimize.height = btnMinimizeImageObj.height;
btnMinimize.setStyle("upSkin", btnMinimizeUpSkin);
btnMinimize.setStyle("overSkin", btnMinimizeDownSkin);
btnMinimize.setStyle("downSkin", btnMinimizeDownSkin);
btnMinimize.addEventListener(MouseEvent.CLICK,
minimizeHandler);
btnMinimize.focusEnabled=false;
btnMinimize.visible=true;
rawChildren.addChild(btnMinimize);
Questions:
1) For the buttons I add (e.g. btnMinimize) ... if I don't
explicitly set the width and height, they default to 0 and button
is invisible. Button class says it should size in accordance with
the image. Is this normal behavior?
2) Along the lines of #1 above, if I just create btnMinimize
and give it a text label (no image), the button sizes to a width
and height of 0. I have to set the width and height for it to
appear? Is this normal behavior?
3) I can't include a screen clip here but the close button
succesfully uses the images I provide but it is larger than the
other buttons (and the image is distorted). Can I set the height
and width of the close button to match the image I'm providing (or
conversely can I get the height and width of the close button so I
can size my buttons the same)?
Spent a few days and I'm getting nowhere ...
thx in advance for any help ...Hi Laxmi,
User has no control on OVS window.You can't add your custom button on OVS window.In OVS Listener implement the three life cycle methods i)onQuery ii) applyResult and iii) applyInputValues which are predefine.
Regards,
Mithu -
Adding a listener to an integer value?
Hello All
Is there a way of adding a listener to an integer value that produce an event (run a method with the object) when an integer value is changed? (Through a object.setValue(int) for example)
Thanks for any help,
Harold ClementsCan any of the kilo-posters (that's with two o's) say if it's considered
bad form to reuse a class that already exists - albeit for a slighty
different purpose? What I'm thinking is that the SpinnerNumberModel
is rather close to what's being looked for - the differences being that
it'll handle any Numbers and has a "next" functionality that we ignore.
Something like:import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class NumberEg extends JFrame {
private SpinnerNumberModel intModel;
private Random rand = new Random();
private JLabel aLabel;
public NumberEg() {
// a thing that responds to changes - there could be
// many of these
aLabel = new JLabel("I respond to changes...");
add(aLabel, BorderLayout.CENTER);
// the thing which changes
intModel = new SpinnerNumberModel(0, null, null, 0);
// a change listener which glues the two previous
// together - again there could be a number of these
intModel.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent evt) {
aLabel.setText(intModel.getValue().toString());
// Meanwhile events like button clicks *cause* the
// changes
JButton but = new JButton("Click me!");
but.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
intModel.setValue(rand.nextInt());
add(but, BorderLayout.NORTH);
but = new JButton("Reset");
but.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
intModel.setValue(0);
add(but, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
public static void main(String args[]) {
NumberEg test = new NumberEg();
test.setVisible(true);
} -
Adding and removing children with buttons
So I've been following this tutorial (http://www.danfergusdesign.com/classfiles/oldClasses/VCB331-richMedia1/exercises/addingChi ldren.php) on how to add and remove children with buttons in order to create a popup box on the stage.
The part I'm having trouble with is how I add the close button to the stage on top of the popup box.
This is basically what I'm trying to do:
Here's my code right now:
var OrderPrepOnlineMenuInstance:OrderPrepOnlineMenu = new OrderPrepOnlineMenu();
var mcOnStage:Boolean=false;
loadOrderPrepOnlineBtn.addEventListener(MouseEvent.CLICK, loadMC);
OrderPrepOnlineClose.addEventListener(MouseEvent.CLICK, removeMC);
function loadMC(MouseEvent):void {
addChild(OrderPrepOnlineMenuInstance);
OrderPrepOnlineMenuInstance.x = 465;
OrderPrepOnlineMenuInstance.y =230;
mcOnStage=true;
function removeMC(MouseEvent):void {
if (mcOnStage ) {
removeChild(OrderPrepOnlineMenuInstance);
mcOnStage=false;Why not just make the close button part of the object you are adding. You can assign it an event listener thru that object after it is created.
-
hey guys please telme how to make the close button on the title bar work
sorry friends it was a real silly mistake and i have got the solution for it, i added window listener to get the windowevents but didnt regester it with my frame,
thx fr giving ur time
1ce again srry -
How to avoid the "Save As" dialog when using "Close Button"
Hello All,
I am facing a problem while closing a pdf file.
I am using the following code to Open a pdf file.
CAcroApp objAcroApp = new AcroAppClass();
CAcroAVDoc objAVDoc = new AcroAVDoc();
objAVDoc.Open(C:\\new.pdf,Sample);
objAcroApp.Show();
After opening the document I am **** some changes (adding markup) in the file.
Then I am closing the file using the Close Button and in YES for the save confirmation dialog.
Here is the problem.
After giving YES, I am getting a Save As dialog with "Sample.pdf" in the FileName box.
I am getting this only in Acrobat 9.0.
When I tried the same in Acrobat 8.0 I didnt get Save As dialog. It saved with out "Save As" dialog in "C:\\new.pdf".
I need to give the same behavior in both Acrobat 9.0 and 8.0.
Please help me out to fix this issue. Thanks in advance.
Regards,
Mohd Mustafa SKIn what you have posted, there is no reason it shouldn't work the same way in Acrobat 9. I would recommend that you submit your complete application to developer support.
-
Is it possible to change the size of the 'Close' button in Full Screen viewing mode?
I am currently using Firefox for a kiosk type scenario. We require that the browser run full screen. The issue is that the 'Close' button is not large enough for users to consistently see, so they're having issues figuring out how to close an active browser window.
Can anyone tell me if it's possible to change this icon? I've tried using themes, but they tend to theme everything but the close button.
Custom configuration details are below.
Firefox version: firefox-3.0.4-1.el5.centos
Customisations:
Access to local drives disabled:
Modified the contents of /usr/lib/firefox-3.0.4/chrome/browser.jar, so that browser.js has the added stanza:
<pre><nowiki>if (location.match(/^file:/) ||
location.match(/^\//) ||
location.match(/^resource:/) ||
(!location.match(/^about:blank/) &&
location.match(/^about:/))) {
loadURI("about:blank");
}</nowiki></pre>
Various menus & bookmarks disabled in chrome/userChrome.css
<pre><nowiki>/* Kill "normal" bookmark icons in the bookmarks menu */
menuitem.bookmark-item > .menu-iconic-left {
display: none;
/* kill icons for bookmark folders in Bookmarks menu */
menu.bookmark-item > .menu-iconic-left {
display: none;
/* kill icons for bookmark groups in Bookmarks menu */
menuitem.bookmark-group > .menu-iconic-left {
display: none;
/* Remove the Edit and Help menus
Id's for all toplevel menus:
file-menu, edit-menu, view-menu, go-menu, bookmarks-menu, tools-menu, helpMenu */
helpMenu { display: none !important; }
tools-menu { display: none !important; }
file-menu { display: none !important; }
edit-menu { display: none !important; }
view-menu { display: none !important; }
go-menu { display: none !important; }
bookmarks-menu { display: none !important; }
#autohide-context { display: none !important;}
#bookmarksToolbarFolderMenu { display: none !important;}
#organizeBookmarksSeparator { display: none !important;}
.tabbrowser-tabs .tab-icon {
display: none;
#urlbar {
font-family: Arial !important;
color: Black !important;
font-size: 26 !important; }</nowiki></pre>Try code like this:
<pre><nowiki>#window-controls .toolbarbutton-icon {
width: 25px !important;
height: 25px !important;
</nowiki></pre>
The three buttons have these IDs:
<pre><nowiki>#minimize-button
#restore-button
#close-button</nowiki></pre> -
Cap2, exe close button not working
I'm publishing to an exe, and I have a disclaimer page where
I want the user to choose between agree & disagree. Agree is
easy, I added a button, on success: continue. With Disagree, I want
the whole project to close, so I looked up the code for making a
close button with the following typed in the javascript box
"javascript:window.close()". Now, when I click on the button it
opens Internet Explorer and then displays the following error
message: "Internet Explorer cannot download . Unspecified error."
So I ran through the forums looking for some help & I've
since changed the javascript to show "window.close()", then
"windows.close()", and still, same error message & the project
still doesn't close.
What am I missing?
Thanks.Hi B Ellefson
Are you sitting down? I hope so because this one is pretty
easy.
Just click Project > Preferences... > Start and End tab
and configure the action for when the movie ends to be "Close
project". Then configure that "Disagree" button to simply jump to
the last slide. You might even wish to make that last slide really
short from a timing perspective. Maybe .1 seconds or so.
With this approach, your .EXE should close quickly, quietly
and consistently.
Cheers... Rick -
How To Use a Custom Close Button In Window Component
Hello,
I have a window component, with the default close button
turned off, and a new custom close button added to the movie clip
that is displayed inside the window component. How do I get a click
on the close button to close the window?
This is the code I currently have to create the window (and
the listeners to close the window using the default close button):basicalyyou have to use
myWindow.deletePopUp();
if my memory serves the content mc is loaded into a mc called
contentHolder, inside the window component, so
if you are referencing the window from the scope of your
loaded mc it will be
this._parent._parent.deletePopUp();
or if from the button's scope
this._parent._parent._parent.deletePopUp();
try traceing the parantage down til you hit the window. -
I am using a Microsoft Natural 4000 Keyboard
IF I update to Mozila 5.0 when i use the close button it shuts down the whole browser nut just the active tab
Is there a workaround for this because I like the close button featureCould you try disabling graphics hardware acceleration? (I'm having trouble determining from your "More system information" whether it's enabled or disabled.) Since this feature was added to Firefox, it has gradually improved, but there still are a few glitches.
You usually need to restart Firefox in order for this to take effect, so save all work first (e.g., mail you are composing, online documents you're editing, etc.).
orange Firefox button ''or'' classic Tools menu > Options > Advanced
On the "General" mini-tab, uncheck the box for "Use hardware acceleration when available"
If you restart Firefox, is the issue resolved? -
Disable/enable window close button?
I have a new Window() open and I want to disable the close button when the window has already been opened. Does anyone know how to do this in Flex?
Ok I got, it's an AIR app.
You can listen to event Closing and preventDefault on it. Check this:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
closing="closingHandler(event)">
<fx:Script>
<![CDATA[
protected function closingHandler(event:Event):void
if(!forceClose.selected)
event.preventDefault();
]]>
</fx:Script>
<s:CheckBox id="forceClose" label="Force close" />
</s:WindowedApplication>
Regards,
Pablo Souza -
[Android] Prev button and close button in lock mode
Hi Some improvements about the user interface on android devices
When my mobile is blocked (Spotify running in the background ) there is not a prev button, only next button .
Some times I want to listen a song again so I have to unlock my phone in order to do this, which is a little annoying.Another thing is the next button, it's next to the close button , some times I try to listen the next song and by mistake I ended up closing the app.
So my suggestion is to put the prev button and move the close button to the other side of the widget.Updated: 2015-07-28Hello and thanks for the feedback!
Any news regarding this request will be announced in the original idea topic here:
https://community.spotify.com/t5/Live-Ideas/Improve-location-of-lock-screen-widget-buttons/idi-p/1012643
Please add your kudos and comments there, if you haven't already. ;) -
"Close" button in Tooltip Widget not working
HI, I hope I'm not doing something stupid here...
It's my understanding that choosing "Stay On Rollout" in the trigger options for a widget and adding a "Close Button" would basically give you tooltip that fades in and stays open until the close button is clicked—fading it back out. If this thinking is correct than the functionality is broken in the Tooltip widget. Running Mac OsX 10.7.3Muse support staff answered this almost 8 months ago on their old support wiki.
http://support.muse.adobe.com/muse/topics/close_button_doesnt_work_on_any_widgets
Close button does not work, they realize that but just haven't come out with a fix yet. There is a messy work around - you kindof have to hack your tooltip widget a bit. But here is the explanation below:
I found a wonky work-around. Instead of closing, I put a next button and made the second tooltip blank. With the type tool, I changed the ">" for next to a "x" and made it the same color as the background so it would disappear into the background after "closing".
Maybe you are looking for
-
Where is the subtitle option in iTunes 12.0.1
Where is subtitle option in iTunes 12.0.1?
-
Wireless connection not detected by networkmanager
Something wrong with my network connections. I've done this like a hundred times (I'm pro at messing up my system and reinstalling) but this time just cannot figure out, gnome netwotk manager installed somewhat broken. because everytime i hit "cancel
-
I have recently started a solaris. I have a solaris using 64x and 86x systems and have java. The machine is very active and is very quick. I am happy so far with its performance and think its worthwhile to continue with my projects. That's all I have
-
Print at Home or Costco?
I have been holding off buying a printer (Epson 2880) because of the numerous complaints and problems with printing reported on the forum. In the mean time, I am exporting my photos to Photoshop in ProPhoto, 16 bit, Sharpened for output and opened in
-
My son gave me his airport express router and I use it to connect to the internet, but I cannot add the security since I don't have the CD that contains the Airport Utility (didn't even konw what this was until I checked apple website). Can I downloa