swing

"Buffers have not been created" ... whilst creating buffers.

I have (what I thought was) a straightforward BufferStrategy for a JFrame. It is created like so: // Buffer container.createBufferStrategy(2); strategy = container.getBufferStrategy(); However, occassionally I receive the following error (which points to the first line of the preceeding snippet as the offending ...

Java KeyEvents for a KeyPad component

I'm writing a Java application that will have an on-screen number pad available for touch-input. Normal key input will also be available, but I'd like the keypad there for tablets and such. I've made a class that extends JPanel. It has 10 buttons laid out in the normal keypad configuration. Now I'm trying to figure out how to make it ...

GUI layer vs Code layer vs Swing

I always coded console applications and learned some basic UML/patterns skills, using C++. Now I decided to move to Java and add GUIs to my programs. The first question is how to handle the GUI layer in the program desing. I mean, how I should separate all the GUI code (adding components, basic event handling) with the code that really...

how to perform mouse on click action in selected area in java paint using swings

import java.awt.*; import java.awt.image.*; import javax.swing.*; import java.awt.event.*; public class MouseAct extends JFrame{ public static void main(String args[]){ MouseAct M= new MouseAct(); M.paint1(); } public void paint1(){ setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setSize(640,480); // show(); ...

Java - Custom Shape Panels?

I am working on an application that involves the user requiring to hover over several moving dots on the screen in order to launch specific popups. At the moment, i am listening for mouseMoved events on the JPanel onto which the dots are rendered, and then launching the required pop ups whenever the cursor is within a specific distance o...

using mvc in swing application

Hi: I want use the mvc in my swing application,however I am counfing after reading some ariticls: http://www.oracle.com/technetwork/articles/javase/mvc-136693.html This is the first paper I read, and I think it is clear enough. However when I start my own work, I do not know how to start. How to decide the number of the view. controlle...

Can I create a layer like on websites using Java Swing?

I want to create a layer in Java Swing which will be displayed when I move my mouse over a specific region on editor pane. ...

JList throws ArrayIndexOutOfBoundsExceptions randomly

I'm trying to add items to a JList asynchronously but I am regularly getting exceptions from another thread, such as: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 8 Does anyone know how to fix this? (EDIT: I answered this question because it's been bugging me and there is no clear search engine fri...

Open source Swing GUI builder that uses MiGlayout

Is there an open source Java swing GUI builder that uses MiGlayout as it's layout manager? I've been trying to learn to make Swing GUI's by hand using MiGlayout but feel it would be easier to learn if the code is auto-generated. Note: I'm not using the GUI builder for my applications, just to see how the code is generated and then apply...

JButton updating its own isEnabled value

I'm trying to create a sub-class of the JButton component that will enable or disable itself based on a condition (which looks like below) public interface Condition { public static final Condition TRUE = new Condition() { public boolean test() { ...

Passing font to components on a JPanel

I have a class that extends JPanel with several buttons on it. I would like to be able to set the font on all the buttons with one call to setFont(Font font); I defined the setFont method in the JPanel class as such: public class MyPanel extends JPanel { private JButton[] buttons = new JButton[10]; public MyPanel() { f...

Problem about SpringLayout in java 1.4.2

public static void main(String[] args) { // TODO code application logic here JFrame frame = new JFrame(); SpringLayout layout = new SpringLayout(); frame.getContentPane().setLayout(layout); TitledBorder border = null; border = BorderFactory.createTitledBorder("Group1"); frame.setSize(6...

JComboBox submit value like HTML select

I have a table with two columns - id and desc. Is it possible to show a list of desc column values to the user in a JComboBox and when the user selects an item from the list and clicks a button, I get its corresponding id value? That is, is it possible to do something like this in Swing? <select> <option value="1">Hi</option> <option...

How to modify the clip string ellipses used by Swing when laying out text components.

By default Swing uses ellipses "..." to indicate that text has been truncated in JLabel and similar text based components. Is it possible to change this behavior to use a different character string, for example ">"? Looking through the Swing code I found in SwingUtilities2 a method called clipString(...) which appears to hardcode the st...

How to modify the clip string ellipses used by Swing when laying out text components.

By default Swing uses ellipses ... to indicate that text in a text field has been truncated. Is it possible to modify this behavior so that Swing uses a different clip string? For example to use > instead of ... SwingUtilities2.java has a method called clipString() that appears to perform this truncation and addition of "...". Unfortuna...

about column's width of a JTable in a JScrollPane

i want to set each column of a JTable in a JScrollPane with a fixed num width, but i cannot do it with infoTable.getColumnModel().getColumn(0).setPreferredWidth(10); i use the default layout of JScrollPane and add the table with the scrollPane's setViewPortView(infoTable) in j2se 1.4. How can i get this done? here is my code private ja...

JMenu and JMenuItems have thin orange border that I cannot change

Hey all, I have been using the UIManager to change the coloring scheme on my GUI. For example I use this for JMenuItems: UIManager.put("MenuItem.foreground", new ColorUIResource(255, 255, 255)); UIManager.put("MenuItem.background", new ColorUIResource(51, 51, 51)); UIManager.put("MenuItem.selectionBackground", new ColorUIResource(232, ...

Minimizing a supplementary JFrame when main application JFrame gets minimized

The application I'm working on contains a main JFrame, from which users might eventually open another supplementary frame. I am trying to implement such a behavior of the app where the supplementary frame is minimized (iconified) as soon as the main frame gets minimized. I was thinking of overriding the setExtendedState method of the ma...

Netbeans GUI Builder with Java Swing; What's the easiest way to organize Widgets?

I'm developing a GUI application rapidly using a GUI buidler (Netbeans). I am frustrated with the Swing widgets... when I resize one the rest seem to "reorganize" themselves in the wrong places. What do you guys use to tame such chaos? I was thinking of tables.... but couldn't find any in the Netbeans Palette. Regards ...

JScrollPane in a popup window does not scroll up programmatically

I have a popup menu that displays dynamically created custom JPanel objects in a JPanel in a JScrollPane. The popup menu displays recommendations to the user and the topmost element is the most relevant recommendation. I am using JPopupMenu to display the window: JPanelTemplatePopup jptep = new JPanelTemplatePopup(); JPopupMenu popup = ...