Getting Graphics Context



I am new to Java and as an exercise I am trying to develop the following: 2 JPanels on a JFrame where 1 of the JPanels can be used for drawing. I started from an example from Daniweb from 2010 but can't seem to get a graphic context because the compiler gives me a null pointer exception. The program compiles and runs fine with the g.drawRect(100,0,150,50); commented out. The broader question is, how do I tell the program that I want to draw in a specific panel? My code is enclosed -- what am I doing wrong? Thanks, Bobonoinc



```
import java.awt.*;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.FlowLayout;

         
public class LinePaintDemo extends JPanel{

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLUE);
        g.drawLine(0, 0, getWidth(), getHeight());
        g.drawLine(getWidth(), 0, 0, getHeight());
    }

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new JFrame();
            frame.setSize(300,300);                  
            frame.setLayout(new FlowLayout(FlowLayout.LEFT));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JPanel contPanel = new JPanel();
            contPanel.setBackground(Color.red);
            contPanel.setPreferredSize(new Dimension(50, frame.getSize().height));
            frame.add(contPanel);

            LinePaintDemo canvase = new LinePaintDemo();
            canvase.setBackground(Color.green);
            canvase.setPreferredSize(new Dimension(200, frame.getSize().height)); 
            frame.add(canvase);

            Graphics g = canvase.getGraphics();
//       g.drawRect(100,0,150,50);

            frame.setVisible(true);
        }
    });
  }
}
```
```
frame.setVisible(true);
Graphics g = canvase.getGraphics();
g.drawRect(0,0,50,50);
```

Getgraphics take graphics when frame is visible, You just have to get graphics after setting it visible.... Simple Solution :)
looking around i think i found the answer myself.

there is are batch and script files in jabref/runtime/bin.

from those, the needed command line call can be derived. using the shipped jvm from inside the mentioned folder the call i looked for would be:

java --add-opens=javafx.controls/javafx.scen… this is my first time digging into the processing source code so i hope this helps. the problem you are facing is more of a java problem though than a processing one.

by extending pgraphics you would have to replace the renderer implementations to inherit from your subclass(tgraphics) and not pgrap… void alpha\_0\_beta\_and\_c01(){

// groot->setstyle("plain");

gstyle->setoptfit(1111);

auto c1= new tcanvas("c","bpre",10,10,600,600);

c1->divide(1,1);

c1->settickx();

c1->setticky();

c1->settitle("");

c1->setlinewidth(3);

c1->setbottommargin(0.1);

c1->settopmargin(0.05)… okay, so here’s what i created to “fix” the readability.

in the window paint event add this code for each control you wish to see better.

if color.isdarkmode and lightskin then

var r as double = popupmenu1.height-20 // just in case the height got larger than 20 (macos default)

g.drawingcolor =… hi,

i can compile your code without error.

could you help to double check your makefile and environment?

environment is set by jetpack2.3.1

topic\_988388.cpp

#include "nvxio/application.hpp"

#include "nvx/nvx\_opencv\_interop.hpp"

#include <opencv2/imgproc/imgproc.hpp>

std::vector<cv::mat> tovisi… Let's say in your `settings.py` file you have:



```
SITE_URL='www.mydomain.tld/somewhere/'
SITE_NAME='My site'

```

**If you need that in just one or two views:**



```
from django.shortcuts import render_to_response
from django.conf import settings

def my_view(request, ...):
    response_dict = {
        'site_name': settings.SITE_NAME,
        'site_url': settings.SITE_URL,
    }
    ...
    return render_to_response('my_template_dir/my_template.html', response_dict)

```

**If you need to access these across a lot of apps and/or views, you can write a context processor to save code:**


James has a tutorial on this 
[online](http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/).


Some useful information on the when and if of context processors is available on this very site 
[here](https://stackoverflow.com/questions/831301/when-is-it-appropriate-to-use-django-context-processors).


Inside your `my_context_processors.py` file you would:



```
from django.conf import settings

def some_context_processor(request):
    my_dict = {
        'site_url': settings.SITE_URL,
        'site_name': settings.SITE_NAME,
    }

    return my_dict

```

Back in your `settings.py`, activate it by doing:



```
TEMPLATE_CONTEXT_PROCESSORS = (
    ...

    # yours
    'my_context_processors.some_context_processor',
)

```

In your `views.py`, make a view use it like so:



```
from django.shortcuts import render_to_response
from django.template import RequestContext

def my_view(request, ...):  
    response_dict = RequestContext(request)
    ...
    # you can still still add variables that specific only to this view
    response_dict['some_var_only_in_this_view'] = 42
    ...
    return render_to_response('my_template_dir/my_template.html', response_dict)

``` May as well promote my comment to an answer.


You need to add points to a `Curve2D` object, then adjust the control points of the curve, and then finally draw the curve. So here's some simple, almost pseudo code:



```
var array_of_line_points # This already has the vectors which describe our line
for point in array_of_line_points:
  # The "get_perpendicular_vector()" function returns a vector that's a copy of the point, yet has been slid along a line parallel to two neighboring points. The "distance" variable is how far the control point should be from the originating point.
  var control_point1 = get_perpendicular_vector(point, distance)
  var control_point2 = get_perpendicular_vector(point, -distance)
  curve.add_point(point, control_point1, control_point2)
# ...In the draw function
func _draw():
  draw_polyline(curve.get_baked_points(), red, 2.0)

```

I got the inspiration for this from [Rob Spencer's page on Spline Interpolation](http://scaledinnovation.com/analytics/splines/aboutSplines.html). I'd like to make this more thorough (i.e. defining the `get_perpendicular_vector()` function). But this is the best I can currently do. hi eric, - - can you elaborate how you are getting a reference to the diagram? are you doing it in the way shown in the demo, in the diagram\_load() handler? the code below can be found in the scripts.js tab of this demo: - - var jsontextbox, diagram; -   -   function diagram\_load(sender) { -       diagram = sender.get\_kendowidget(); -   -       diagram.layout({ -           type: tree, -           subtype: left, -           roots: [diagram.getshapebyid(nadal\_winner)], -           verticalseparation: 20, -           horizontalseparation: 30 -       }); -   } - - - - - regards, - vessy - progress telerik - get quickly onboarded and successful with your telerik and/or kendo ui products with the virtual classroom free technical training, available to all active customers. learn more. I have the same problem and added this to the DbContext:



```
private void PrintStackTrace()
{
  var st = new StackTrace();
  foreach (var sf in st.GetFrames())
    Console.WriteLine($"{sf.GetMethod().DeclaringType.Assembly.GetName().Name} {sf.GetMethod().DeclaringType.Name} {sf.GetMethod().Name}");
}

```

and call this function in the contructor and Dispose of the DbContext.


It seems to be a problem, if the DbContext is added with scoped lifetime to the dependency injection. I filed an issue for that.


<https://github.com/aspnet/EntityFrameworkCore/issues/10693> Unfortunatley after many many years of asking for this, Illustrator still has not added this feature to text frame options.

The closest you can get is to draw a rectangle, click with the vertical type tool (But that will only allow you one character per line.)

![Screen Shot 2016-04-13 at 3.23.20 PM.png](/legacyfs/online/910043_Screen Shot 2016-04-13 at 3.23.20 PM.png)

You could do this with the align palette. You would need to select another element to align against (eg: a rectangle filled with none). You need to add an outline effect to the type, and in the align flyout menu turn ON use preview bounds.

![Screen Shot 2016-04-13 at 3.30.11 PM.png](/legacyfs/online/910045_Screen Shot 2016-04-13 at 3.30.11 PM.png)