Make the JTable cell ready to be overwritten - swing

I have a button which inserts a single column row into a JTable with the text:
"New notes: ". I want this text ready to be overwritten as soon as the user starts typing on this cell (rightafter the button-press). How to make the JTable's cell ready to be overwritten? How can this be done?
Thank you!

You will need to use a custom TableCellEditor, when getTableCellEditorComponent is called, if the value is null, you would seed the editor with your prompt and call the selectAll method (assuming you are using some kind of JTextComponent for the editor).
This may require you to call selectAll within a SwingUtilities.invokeLater call.
Alternatively, you could have a look at this prompt API

Related

A way to require dbc.Input to receive an updated value before triggering a callback while using debounce?

I have a large, dynamic number of dbc.Inputs (~200) that trigger a callback.
Their id’s use pattern matching callbacks.
The value entered in the input updates a SQL db.
The problem I am facing:
I need to have debounce=True so that every keystroke doesn’t trigger the callback.
However, having debounce=True also makes it so that if the Input is clicked into, and clicked out of without any changes being made, it still triggers the callback.
Is there any way to make it so the callback only triggers if the current value has been changed? I was hoping this could be done within the args of the input itself but did not see any args that would achieve this.

Linking a Macro TBD

Can you insert a Macro command into a link?
I see you can create a button via "insert drawing" and additional script details but I like to click a link and it performs my macro.
You could create a web app and use it's end point url to call any of your functions by name through the use of the parameters in the query string.
You could use the onSelectionChange(event) trigger. If you move the cursor and click on a cell it will tell you which cell was clicked and you could associate another function with that cell. If you click in the same cell it won't do anything.
However what I find is, although it is a simple trigger, you have to close and reopen the Spreadsheet for it to become active.
function onSelectionChange(event) {
// event = {"range":{"columnEnd":3,"columnStart":3,"rowEnd":1,"rowStart":1},"authMode":"LIMITED","source":{},"user":{"email":"xxxx#gmail.com","nickname":"xxxx"}}
Logger.log(JSON.stringify(event));
}

Sourcing a value from a list box and passing it onto an object on a form

I would like to take a numerical value found within a list box i have on a form and bring it into a text box on the form itself. I would like to to this to then use that value as a unique ID number to link to one of the sub forms found on the form. Is it possible?
I have something like this on one of my forms, I would suggest setting it to a global variable and then using that variable as a control Source.
in VBA create a module and call it something.
Public Function Something() As Variant
'Finds the Current Selected value from Form Element
Something = Forms("MainMenu").texbox.Column(1) ' 0 is the First Column
End Function
This is what will store your variable. Then you need to call it from your form. If your wanting to pass it to another form i am assuming you have a button or something that calls the other form to open. On the same trigger before any of your other code is ran you need to put:
Call Something
When you call it, it will set what ever value is in your textbox to that variable.
Once you have this variable stored you would simply put in the control source of the textbox on your other form:
=Something()
Then when ever your other form is activated it will display what ever ID was stored in the variable.
Just remember if you direct your user away from your form to re-set the variable to nothing.

Passing in a Parameter in Google Spreadsheet Script from Script Assignment

I'm trying to make my own button in a Google Spreadsheet, and I have a script called incrementContents that takes in a parameter (a cell location, eg 'B3') and increments that location by one.
My question is this- is there a way to pass in a parameter to this function via the same text box where I assign the script to the button (right click -> assign script)? Something like;
incrementContents('B3')
or
incrementContents, B3
I'm not sure of the syntax, and knowing how to do this would be very helpful.
You could do a couple of things -
Ask the user for the input using Browser.inputBox
Read cell's value from the script itself (if the cell reference is always constant) using an example like SpreadsheetApp.getActiveSheet().getRange("A1")
The way I am trying to work around this problem is by having the user edit a cell instead of adding a button to the cell. (Eg. typing "ok" in the cell.) This triggers the onEdit() function or a custom function that is passed the event parameter that can be used to get data from the sheet relative to the cell where the "ok" was entered.

Google Spreadsheet Script not Updating Dynamic Info

So, i made a spreadsheet for Minecraft and 'Feed The Beast' a modpack for the game. My spreadsheet lists all the mods that are updated for the latest version of Minecraft. Recently i made a script to go out and parse pages for mod version numbers. They change hourly-daily and i rather not do it manually.
function GetVersion(url, slice, num1, num2) {
var r = UrlFetchApp.fetch(url).getContentText();
var version = r.slice(r.indexOf(slice)).slice(num1, num2);
return version;
}
In one of the cells Ill have the following
=GetVersion("http://files.minecraftforge.net", "Build 7.", 12, 15)
Now this works fine and gets me the version number im looking for. The problem is, when an update happens and a new version comes out, the parser doesn't reflect this even if i close the window and reopen the spreadsheet or reload or whatever else! If I change the above slightly, like change the 15 to 16, it will refresh, but then will be stuck there again until i manually change it again.
How do I get it so it at least refreshed when i reload the sheet?
Edit: Alright first I tried to go into reosources and triggers and make a trigger very min and everytime the doc is opened. This didn work..............
Then I tried to get clever. Noticing that the formula reevaluates whenever I change it, i surmised that the formula itself or the cell parameters needs to change in order for this to happen. So I pass a dummy parameter though in the formula and change that parameter to update the cell.
But that's annoying and make me have to edit (or press a button) just to get shit to refresh.
So i got a brainwave and Im now passing GoogleClock() in the dummy parameter. All cells now update on their own every 60 seconds. yay
Is there a better way to do this?
Using googleclock as a param is the best u can do if u want to use a custom cel formula.
Instead call an update function from a menu item and/or onOpen / time trigger.
Aside from the workaround of passing GoogleClock() as a parameter (which I agree is the best you are going to do with a custom function), the other option is to do away with a custom function, and use GAS to write the result directly to a cell, eg:
SpreadsheetApp.getActiveSpreadsheet().getRange('Sheet1!A1').setValue(version);
Then in Resources, Current project's triggers, you can set both an "on edit" and time-driven trigger (to be clear: these triggers won't work on a custom function called from a spreadsheet cell; all the "work" must be done by the script itself).