JComponent « JComponent « Java Swing Q&A





1. How to create a custom Swing Component    stackoverflow.com

I've always wanted to create custom components in Java, or customize existing ones, but my searches never resulted in anything useful. So I decided to ask the StackOverflow community: Where can I ...

2. JComponent: How can it resist smallification?    stackoverflow.com

I have a custom JComponent that paints some stuff when paint is called. In a Border layout, though, it's minimumSize is not being respected. I've included this

@Override
public Dimension getMinimumSize() {
  ...

3. getting information from different JComponents    stackoverflow.com

i have a GUI that is mainly a survey, when the survey is finished the information would be extract to a table , i am currently having trouble getting all the ...

4. Help with rendering the Mandelbrot set in Java    stackoverflow.com

I wrote an implementation of the Mandelbrot set in Java using a JComponent but I'm getting strange results when I render it. Besides that everything compiles right. I'm just not for ...

5. JComponent.revalidate() doesn't update until code finishes    stackoverflow.com

**Hello, I'm trying to create an archiver in java. This means that I am constantly reading and writing from streams. I want to be able to update a JProgressBar to ...

6. java.lang.noclassdeffounderror for JComponent mock class    stackoverflow.com

HI, I'm getting a java.lang.noclassdeffounderror when trying to create a mock class for Component using EasyMock. private Component mockComponent; @SuppressWarnings("restriction") @Before public void setUp() { mockComponent = EasyMock.createMock(Component.class); } Can anybody help ...

7. SetTitlePosition on the left of a JComponent    stackoverflow.com

Is it possible to place a title on the left (or right) of a JComponent? I don't mean justification but the real position.. I tryed setTitlePosition(TitledBorder.LEFT) on the TitledBorder associated with the JComponent ...

8. Java custom JComponent: Why is getMinimumSize() ignored?    stackoverflow.com

I've overridden getPreferredSize() and getMinimumSize() in my custom JComponent. While getPreferredSize() is working as expected, getMinimumSize() instead is ignored as I am able to resize the JFrame until my custom component ...

9. What's the rule of thumb regarding Swing component extension?    stackoverflow.com

When dedicating a class to a particular Swing component, is it better to extend that particular component, or construct it internally and provide a reference?

public class Foo extends JComponent{

}
OR
public class Foo{
 ...





10. How to use z axis?    stackoverflow.com

I have a code, which imports a brain image, I wanted to know that can how can I use the third axis, i-e z axis, (far and near axis) so that ...

11. Jcomponent divison    stackoverflow.com

I want divide jcomponent into different parts

public TaskGraphComponent(ProjectFrame proFrame,TaskGraphModel    model,TaskGraphPainter    painter) {
    this.proFrame = proFrame;
    _painter = painter;

 ...

12. Reusing of components in Java not properly trimming un-reused ones    stackoverflow.com

I have a javax.swing.JPanel called calcResPanel (using a java.awt.GridLayout with 1 column and indefinite (0) rows) which is to receive and display a set of BHSelectableLabels (which extend javax.swing.JTextField) with collectively ...

13. What JComponents to use..?    stackoverflow.com

Till now, I was using VB for developing applications. Now I have to use Java for developing the front-end. I am quite confused with the Components. Need help.. A book reference ...

14. Rounded corners for JComponents    coderanch.com

15. creating custom JComponent    coderanch.com

16. Which JComponent should i use for this??    coderanch.com

Hi , i am working on one problem which is having a need that.. after clicking on the button one small window should popup asking for some data (by the time he shouldn't be able to work with background window) he could cancel the small window or feed the data.. here i want something like prompt(" ","") in Javascript.. i tried ...





17. Custom JComponent problem    coderanch.com

18. Setting the Z order of a JComponent    coderanch.com

19. Animating Swing JComponents    coderanch.com

20. Getting JComponents    coderanch.com

Then you arn't doing something right... I can't tell what the 'gaps' variable is supposed to do in your component, but you should be looping through the entire array you get back from 'getComponents()' not '2*gaps'. Here is a short example that shows that this works : import java.awt.BorderLayout; import java.awt.Component; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Iterator; ...

21. JComponents not work at client PC    coderanch.com

22. JComponent.setDefaultLocale doesn't work    coderanch.com

Hi, My application includes internationalization support for several languages. At startup, I read the system property "user.language" to get the user's default language. That works fine. I also have a button, where one can change the language. Changing language means, another bundle is loaded. That also works fine. For several dialogs I use JOptionPane.showInputDialog() and other methods from the same class. ...

23. Tracking when a JComponent is visible    coderanch.com

24. JComponent problem ?    coderanch.com

//============================================= import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.awt.BorderLayout; public class BasicDraw { public static void main(String[] args) { new BasicDraw(); } BasicDraw() { JFrame frame = new JFrame(); MyComponent fff = new MyComponent(); // Add a component with a custom paint method frame.getContentPane().add(fff); // Display the frame int frameWidth = 300; int frameHeight = 300; frame.setSize(frameWidth, ...

25. Irregular shaped JComponents    coderanch.com

I'm going to start a new project that includes "puzzle pieces". Each piece "interlocks" to another peice, as a real world puzzle would. I need to highlight each piece when the mouse travels over it (using a MouseMotionListener). This is easy to do with square or rectangular shapes, but I've not tried this with odd shape pieces. I could certainly have ...

27. Referencing JComponents programatically    coderanch.com

28. JComponents    coderanch.com

Hi everyone, You see i have some embedded JComponents in a JTextPane, now what i want i want to do is remove the embedded components and then add them back to their original location(i.e where i got them from in the first palce) You see to get the all JComponents i do this JTextpane TextPane1 = new JTextPane; JLabel Label1 = ...

29. Custom JComponent    coderanch.com

ok i have a Battle ship game im doing, and i want each ship be a separate Component... so i can add mouse listeners to them ive extended JComponent and Component... and when i do ship BS = new Ship() // ship extends Component.. this should create an instance of ship with Component attributes right?? please help, what when i do ...

30. Zoomable JComponent    coderanch.com

32. Encapsulating JComponent Instance Variable    coderanch.com

As always, it depends. You probably don't need to provide getters/setters for all of your components. Just take it on a case by case basis. If you have a class that needs access to a member variable of another class then providing a getter for that object might be a good idea. someClass.getLogoutButton(); If you don't indent to provide any logic ...

34. something weird on some JComponents...    coderanch.com

try { Connector conn = new Connector(); Connection con = DriverManager.getConnection("jdbc:odbc:InventoryDB","",""); Statement s = con.createStatement(); s.executeQuery("SELECT * FROM accounts WHERE username IN('"+user+"')"); ResultSet rs = s.getResultSet(); while(rs.next()) { int lvl=rs.getInt(3); String pw = rs.getString(2); if(password.getPassword()==pw.toCharArray()) { JOptionPane.showMessageDialog(desk,"Logged In as"+user); } if(password.getPassword()!=pw.toCharArray()) { JOptionPane.showMessageDialog(desk, "Error in validating user"); } System.out.println("From Password Field:"+password.getPassword()) System.out.println("From Database:"+pw.toCharArray());

35. Custom JComponent Problem    coderanch.com

I believe that this line here: g2.fillRect(this.getX(), this.getY(), this.getWidth(), this.getHeight()); the first two parameters, the x and y are supposed to be relative to this component (the JComponent), not the container (the contentPane). So perhaps you want to use 0 for both x and y here. e.g., my SSCCE: import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; import javax.swing.*; ...

36. can't understand JComponent    coderanch.com

i was making a jcomponent and inside it i drew a rectangle . i wanted to set the background color of the JComponent as red or anything but when i write setBackground(Color.red) and execute the code the color is not set . Can somebody explain why ? My hunch is that it has something to do with the opaque property . ...

37. JComponent.revalidate()    coderanch.com

38. JComponent not opaque    coderanch.com

public class MyCanvas extends JPanel { /** * Protected instance variables */ protected CanvasNode canvasNode; protected UndoManager undoManager; private Dimension dim; // Grid / snap control vars: private CanvasGrid grid; private boolean drawGrid; private boolean drawGridOnTop; public MyCanvas(Dimension dim) { this.canvasNode = TreeManager.get().addCanvas(this); this.undoManager = new UndoManager(); this.dim = dim; this.grid = new CanvasGrid(dim); this.drawGrid = true; this.drawGridOnTop = false; // ...

39. HashMaps containing JComponents    java-forums.org

Hey all, I've got a 2D HashMap, in which there are JCheckBoxes, JButtons, and JTextFields, so it's like: HashMap >. I add JComponents dynamically to it. My goal is to add some listener to the JComponents, which is able to indicate either the user clicked on the button, or checked the checkbox, and to be able to get to ...

40. Using JComponent methods on a JComponent that was found using .getComponents()    java-forums.org

Hello, I am trying to create a class with methods that retrieve components from a container using .getComponents() and then find the values/settings of those components (example: isSelected() from JCheckBox, getText() from JTextField). I will be saving the values into a file for use later (as in saving user preferences). Java Code: import java.awt.Component; import java.awt.Container; import javax.swing.JCheckBox; import javax.swing.JList; public ...

41. JComponent Question    forums.oracle.com

Hi, i am trying to layout some buttons and textfields on my frame. i am currently doing this: private JButton submit; submit.setLocation(200,250); panel.add(submit); but when i run the program, the button is at the sam position, that being, the top of the panel, like when you normally add a button... P.S: i dont have any layout managers overriding any layout settings, ...

42. Why can't I call a method on a JComponent?    forums.oracle.com

Here is the [code|http://gist.github.com/604220]. (Hmm... the URL code by the textfield doesn't seem to work. Try this in stead: http://gist.github.com/604220 ) When I try to run it I get this error: cannot find symbolsymbol : method setWidth(int,int) Shouldn't I be able to call that method after adding the component to a frame? I'm trying to build a DTMF tone detector, and ...

43. Advise for JComponent    forums.oracle.com

44. Declaring a JComponent as Final    forums.oracle.com

45. Problem updating jcomponents    forums.oracle.com

46. Strange behavior on JComponent using MediaTracker    forums.oracle.com

Swing related questions should be posted in the Swing forum. Add components to your GUI before making the GUI visible. If you add components to the GUI after the GUI is visible then you need to use validate() or revalidate() on the parent container to tell the container to layout the components correctly. Sometimes you also need to invoke the repaint() ...

47. Passing references of JComponents to other classes    forums.oracle.com

Sorry for double posting .. This is the exact error msg netbeans gave me [quote] non-static variable carrier cannot be referenced from a static context non-static variable auth_PortTextField cannot be referenced from a static context -- (Alt-Enter shows hints) [/quote] I followed the hints which Changed the carrier.auth_PortTextField to InfoCarrier.auth_PortTextField which still didn't solve the problem. Cannot compile.