How to create a notification in swing

You might need a translucent frame without decorations. Quick demo OSX ] You can take advantage JLabel displays simple HTML import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.*; import java.util.Date; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; /** * Simple demo on how a translucent window * looks like when is used to display the system clock. * … Read more

Removing Icon from a WPF window

From WPFTutorial: How to remove the icon of a WPF window Unfortunately WPF does not provide any function to remove the icon of a window. One solution could be setting the icon to a transparent icon. But this way the extra space between the window border and title remains. The better approach is to use … Read more

How to use HTML and CSS as a Java application GUI?

You can embed web browser component into your Java Swing/JavaFX Desktop application that displays GUI built with HTML5+CSS+JavaScript. You can see an article that describes how to do this at One of the Java Swing/JavaFX libraries that allows embedding Chromium into Java applications is JxBrowser. Using JxBrowser API you can load any web page … Read more

Center JDialog over parent

On the JDialog you’ve created you should call pack() first, then setLocationRelativeTo(parentFrame), and then setVisible(true). With that order the JDialog should appear centered on the parent frame. If you don’t call pack() first, then setting the location relative to the parent doesn’t work properly because the JDialog doesn’t know what size it is at that … Read more

How to get the center of the thumb image of UISlider

This will return the correct X position of center of thumb image of UISlider in view coordinates: – (float)xPositionFromSliderValue:(UISlider *)aSlider { float sliderRange = aSlider.frame.size.width – aSlider.currentThumbImage.size.width; float sliderOrigin = aSlider.frame.origin.x + (aSlider.currentThumbImage.size.width / 2.0); float sliderValueToPixels = (((aSlider.value – aSlider.minimumValue)/(aSlider.maximumValue – aSlider.minimumValue)) * sliderRange) + sliderOrigin; return sliderValueToPixels; } Put it in your view … Read more

Matplotlib plot zooming with scroll wheel

This should work. It re-centers the graph on the location of the pointer when you scroll. import matplotlib.pyplot as plt def zoom_factory(ax,base_scale = 2.): def zoom_fun(event): # get the current x and y limits cur_xlim = ax.get_xlim() cur_ylim = ax.get_ylim() cur_xrange = (cur_xlim[1] – cur_xlim[0])*.5 cur_yrange = (cur_ylim[1] – cur_ylim[0])*.5 xdata = event.xdata # get … Read more

How to clear the Entry widget after a button is pressed in Tkinter?

After poking around a bit through the Introduction to Tkinter, I came up with the code below, which doesn’t do anything except display a text field and clear it when the “Clear text” button is pushed: import tkinter as tk class App(tk.Frame): def __init__(self, master): tk.Frame.__init__(self, master, height=42, width=42) self.entry = tk.Entry(self) self.entry.focus() self.entry.pack() self.clear_button … Read more

At what point is it worth using a database?

A database is worthwhile when: Your application evolves to some form of data driven execution. You’re spending time designing and developing external data storage structures. Sharing data between applications or organizations (including individual people) The data is no longer short and simple. Data Duplication Evolution to Data Driven Execution When the data is changing but … Read more