swing

Netbeans 6.8: Actionlistener confusion

I have 2 modules: BrowserLibrary and BrowserViewer. Browser contains gui like any browser should. so inside BrowserLibrary module I have a class like so: public class BrowserController implements ActionListener{ public void actionPerformed(ActionEvent e) { if (e.getSource().getVarName() == "navButton") System.out...

Create Listener similar to MouseListener

I want to create a listener that works like mouselistener, but it must be a component: F.e. i have two JComponents (One is a button, and second is MyComponent), and i want to do following: button.addMyComponentListener(listener); And if MyComponent for example has moved above button, it must fires an event, or if MyComponent has change ...

JAVA: Put Image in jTable Cell

Hi I need to display an image in one of jTable cells. I wrote this: class ImageRenderer extends DefaultTableCellRenderer { JLabel lbl = new JLabel(); public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { lbl.setText((String) valu...

Java Swing - Can i make a JTable column without borders ?

I have created a column with cells that contain a JTextArea + A JButton inside it, as you can see in the image below in Column 3 : But i have faced lots of problems with my CellRenderer and CellEditor when updating the cells values in that column, as my code is a bit complicated. So instead i want to replace that column with 2 columns...

I can't get my icon to show up in my JLabel swing component.

I am a first time user of Stackoverflow, so please bare with me. Below is the java Swing code to place a icon in a JLabel Swing component. package com.TheMcLeodgrp; import java.awt.FlowLayout; import java.awt.HeadlessException; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel;...

Why running Java UI without SUDO breaks GUI appearance?

Why running application with SUDO changes GUI appearance? I.e.Button background, Button size, JTree appearance are behaving differently depending on how the GUI was started with SUDO or not. Will appreciate your suggestions. Thank you ...

NullPointerException when running multiple Action events

Purpose of the code : Create two Buttons(button1 and button2). When User clicks button1, change the text of button2. When User clicks button2, change the text of button1. Here's the code I'm using : import javax.swing.*; import java.awt.*; import java.awt.event.*; public class multiAL { JButton button1; JButton button2; JFrame frame; ...

use of a JToolTip

I want to use that class and not call on a JComponent setToolTipText method but the code below not show the tooltip: JButton btn = new JButtn("SAVE"); JToolTip tip_for_button = new JToolTip(); tip_for_button.setTipText("blah blah"); tip_for_button.setComponent(btn); why? ...

how to remove Jbutton from the table

Hi I have a table with a column as JButton. i set the renderer as follows TableColumn col = colModel.getColumn(3); col.setCellRenderer(new MyRenderer("Del")); col.setCellEditor(new MultiTradeCellEditor(new JCheckBox())); The renderer and cellEditor classes are class MyRenderer extends JButton implements TableCellRenderer{...

Java Swing JTable sort

I have a JTable with column headers. When I click on a column header the data gets sorted. This is the default sort behavior. The thing is that I need to remember the last column the user clicked to sort. Anyone knows which listener I need to implement in order to catch the column name that user clicked for sorting on the JTable? Th...

Swing changing JTabbedPane to a JPanel

I'm having this strange issue with Swing. I have a main JPanel to which I am adding a JTabbedPane. Inside of this JTabbedPane I am adding another panel: myTabbedPane.add(innerPanel, "Title", 0); outerPanel.add(myTabbedPane); Now, I no longer want myTabbedPane to be JTabbedPane, I want it to be a JPanel. When I change its type (and ...

JTree check for duplicate categories

I'm trying to generate a JTree based on a database result set. I get Category | Name -------- | ---- A | 1 B | 2 A | 3 from the database. How can I add the category to the JTree only if needed? I'd like the tree to look like: [Root] [Category A] Child 1 Child 3 [Category B] ...

(Java) How can I create a Drop Shadow/Inner Glow/Outer Glow similar to Photoshop.

I am generating some images using the Graphics2D interface, and occasionally I'd like to be able to draw some text on the image and apply to it effects like the ones in Adobe Photoshop. Right now to generate a 'shadow' on the text I am drawing the text twice, once in the original color, and once in black with a slight (1px) x&y offset....

Re-firing MouseListener event

I need to store a mouse click event whenever a user clicks on a table column for sorting. I'm basically saving the MouseEven: public void mouseClicked(MouseEvent e_) I store e_ on a global variable so later I can fire that same event and sort the table to the previous user sort action. But when I manually fire the previous stored mo...

Swing load available font family slow down the performance

After I add in this code to load the available font family and add it in to combobox GraphicsEnvironment ge = GraphicsEnvironment. getLocalGraphicsEnvironment(); String[] fontNames = ge.getAvailableFontFamilyNames(); It load very slow took about 7 seconds to show the page when i trigger the page. After i take it out it load fine as...

"MVC" and controlling a jMenubar depending on selected jTabbedpane from a "Control" class

Right so I know my code/structure is pretty messy, I've not done MVC before and I'm pretty sure I've done it wrong anyway. I want to be able to "control" the jMenubar depending on which tab is selected. I have a main GUI class which simply creates a new "MenuBar" and each new "PanelXXXX", where "PanelXXXX" could be "PanelDesign", "Panel...

how to identify JComboBox whether is disabled or enable inside its renderer class

I have a JComboBox contains following iems { "select" , "one" , "two" } i need a separate background for first item so , i have made a condition in it's renderer like public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRenderer...

How to create a notification in swing

Using Java and Swing, is there any (convenient) way to create a notification? By notification, I mean something like: , , or (Is there a more correct term for that?). It would be nice if it worked cross-platform, but I'm mainly concerned with it working under Ubuntu with Gnome. If at all possible, I would like to avoid having an...

When to use EventListenerList instead of a general collection of listeners

When I learned how to fire events in Java, I became familiar with EventListenerList. When I create my own listeners, I write the listener so it extends EventListener, I store them in an EventListenerList, and my fire method would go through the event listeners like this: protected void fireChangeOccurred(Change change) { Object[] li...

Java resizing my splitter frame

I have a jDialog with a splitter inside it. One side has a tree while the other side has a frame. Whenever I use setVisible(false) to hide the frame, the splitter resizes to filled the entire screen with the tree. Is there anyway to keep the tree side of the splitter the same size whether the frame is hidden or not? ...